You need to separate out some things here. The textbox needs a string, and
it needs it assigned not to the textbox itself, but to its Text property.
The database has a date. So, to fetch the date from the database, you need
to use the GetDateTime() method of the DataReader. Then you need to convert
the data returned to a string, using ToString() or Convert.ToString():
txtCustomerName.Text =
MyDataReader.GetDateTime(MyDataReader.GetOrdinal(" CustomerName")).ToString()
txtCustomerName.Text =
Convert.ToString(MyDataReader.GetDateTime(MyDataRe ader.GetOrdinal("CustomerN
ame")))
Hint: Turn ON Option Strict!
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Smith Simson" <Sm*******@yahoo.com> wrote in message
news:Oo**************@TK2MSFTNGP12.phx.gbl...
I am reading the data from database using SqlDataReader.
Here is my code.....
txtCustomerName =
MyDataReader.GetString(MyDataReader.GetOrdinal("Cu stomerName"))
txtCustomerDOB =
MyDataReader.GetString(MyDataReader.GetOrdinal("Cu stomerDOB"))
I am getting the "cast" error at the second line.
the reason for this is "CustomerDOB" is a datetime field in SQL server
dataabase.
how to solve this ? How to read different datatype into Text box. I have
smallint, tinyint in my database.
Thanks for your answer.
Smith