|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
InvalidCastException in DataRowThis is a compactframework windows app. Iam trying read from a DataRow. myTextBox.Text=myDataRow("MyColumn") If there is a value for the myDataRow("MyColumn") then the statement executes. But if the column is empty I get invalidCastException, When casting from number etc.. I have tried CTYPE() or even check for "Is Nothing", just accesing the column gives me the exception. How can I prevent the exception from occuring. Underlying DataField is nvarchar(250) from SQLCE databse. Thanks jay Try
if (!myDataRow.IsNull("MyColumn")) myTextBox.Text=myDataRow("MyColumn"); or myTextBox.Text=myDataRow("MyColumn").ToString(); Show quoteHide quote "Jay Balapa" wrote: > Hello, > > This is a compactframework windows app. > > Iam trying read from a DataRow. > > myTextBox.Text=myDataRow("MyColumn") > > If there is a value for the myDataRow("MyColumn") then the statement > executes. But if the column is empty I get invalidCastException, When > casting from number etc.. > > I have tried CTYPE() or even check for "Is Nothing", just accesing the > column gives me the exception. > > How can I prevent the exception from occuring. Underlying DataField is > nvarchar(250) from SQLCE databse. > > Thanks > jay > > > > > > > Thanks Nate for replying.
It is not working Iam getting the exception on the IF statement you suggested. Here are the details- INVALID CAST EXCEPTION WAS UNHANDLED - COULD NOT FIND RESOURCE ASSEMBLY -jay Show quoteHide quote "Nate" <N***@discussions.microsoft.com> wrote in message news:B6292B49-E924-403F-A592-3C998826A893@microsoft.com... > Try > > if (!myDataRow.IsNull("MyColumn")) > myTextBox.Text=myDataRow("MyColumn"); > > or > > myTextBox.Text=myDataRow("MyColumn").ToString(); > > "Jay Balapa" wrote: > >> Hello, >> >> This is a compactframework windows app. >> >> Iam trying read from a DataRow. >> >> myTextBox.Text=myDataRow("MyColumn") >> >> If there is a value for the myDataRow("MyColumn") then the statement >> executes. But if the column is empty I get invalidCastException, When >> casting from number etc.. >> >> I have tried CTYPE() or even check for "Is Nothing", just accesing the >> column gives me the exception. >> >> How can I prevent the exception from occuring. Underlying DataField is >> nvarchar(250) from SQLCE databse. >> >> Thanks >> jay >> >> >> >> >> >> >> Try it like this...
If Not myDataRow("MyColumn") = DbNull.Value myTextBox.Text=myDataRow("MyColumn") End If Its what i use.
String wierdness...
Access database insert statement with an autonumber (identity) in vb.net Datagrid current row edits Thread Question Thread question trying to download VS2005 from MSDN Exposing a .Net assembly to both VB6 and .Net (1 more time) Does file exist Converting Code from VBA to VB.NET Is RegEx a good choice for reading malformed xml? |
|||||||||||||||||||||||