473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

InvalidCastException in DataRow

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


Jun 2 '06 #1
3 2051
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


Jun 2 '06 #2
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



"Nate" <Na**@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.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


Jun 2 '06 #3
Try it like this...

If Not myDataRow("MyColumn") = DbNull.Value
myTextBox.Text=myDataRow("MyColumn")
End If

Its what i use.

Jun 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Floela | last post by:
I keep geting the exception: System.InvalidCastException: Specified cast is not valid. I get this when I try to pass a DataRow into an object method. The line that causes this error is: ...
3
by: Floela | last post by:
I keep geting the exception: System.InvalidCastException: Specified cast is not valid. I get this when I try to pass a DataRow into an object method. The line that causes this error is: ...
0
by: Jon the Blind | last post by:
I have a set of business object classes built from the typed dataset tool in Visual Studio. Since the individual objects (such as the Order object, for example) inherit from DataRow, a common...
3
by: Jay Balapa | last post by:
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.