Monday, March 12, 2012

How to convert 'System.String' to 'System.Guid'

prm = new SqlParameter("@dotnet.itags.org.passkey", SqlDbType.UniqueIdentifier);
prm.Value = stringvalue;
I got this exception
Invalid cast from 'System.String' to 'System.Guid'
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)prm.Value = new Guid(stringvalue);
"Arne Garvander" <ArneGarvander@.discussions.microsoft.com> wrote in message
news:ACDE0382-BBD1-4AC8-9D99-55445B9F6F49@.microsoft.com...
> prm = new SqlParameter("@.passkey", SqlDbType.UniqueIdentifier);
> prm.Value = stringvalue;
> I got this exception
> Invalid cast from 'System.String' to 'System.Guid'
> --
> Arne Garvander
> (I program VB.Net for fun and C# to get paid.)

Labels: , , , , , , , , , , , , , ,

How to convert SqlDatareader to DataTable

Hello all,

Is there a way to convert a SqlDatareader to DataTable?

I'm not talking about looping through the datareader and add each value into the datatable. For example the dataset, you use a DataAdapter to fill the data into the dataset.

I've read on something like a ovrride the fill function and of the DbDataAdapter ... but it doesn't seem to work ...

protected overridable function(dataTable as DataTable, dataReader as IDataReader) as integer
return Fill(dataTable, dataReader)
end function

Has anyone done this before? Any input is appreciated.

Unfortunately, as far as I know, the answer is no - due to the inherent nature of a DataReader itself. It's a forward only/read once process. If you don't do something with it at the time it's being created, it's gone.

The only way I can think of to take care of that, would be to manually insert the objects into the datatable, as the datareader was being read


David, your icon is scary ... lol. thanks for the respond. please take a peek at this URL:http://msdn2.microsoft.com/en-us/library/497b1k4t.aspx

and also this sample:http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=628

I tried but somehow I can't get it to run. Well, I didn't copy all of the author's code. What do you think?

Labels: , , , , , , , ,

How to convert datareader.items value to integer

Hi,

I have a datareader item

myreader.Item("netcost")

This is a numeric value, I need to take the value and minus 500 from it, I have

(myreader.Item("netcost")-500)

This causes an error, 'cannot cast from string to integer'

How do I do it?

Thanks. BenYou can use Ctype.

For example, this converts you datareader item to an integer.

CType(myreader.Item("netcost"),Integer) - 500
Convert.ToInt32(myreader.Item("netcost").ToString())

Labels: , , , , , , , , , , ,