C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

Regarding null values in the database


Posted Date: 06 Oct 2008      Posted By: Hamar Kharshiing      Member Level: Gold     Points: 1   Responses: 3



Hi,

Im having a to_user field in the table as null..
In my code i am checking it like this using tableadapter.
Dim ta As DataSet1TableAdapters.messageTableAdapter = New DataSet1TableAdapters.messageTableAdapter
Dim dt As DataSet1.messageDataTable = ta.GetMessagesbyroomid(Request("RoomID"))

If Not dt Is Nothing Then

For Each message As DataSet1.messageRow In dt
if message.to_user is nothing then
'do something
end if
next
End if

That means if in one of the rows using for each loop, the to_user field is null then we do something. But it is giving me this error:
"The value for column 'to_user' in table 'message' is DBNull."

StrongTypingException was unhandled by user code..
Hellp me on this..plz..

regards,
Hamar





Responses

Author: Anil Kumar Pandey    06 Oct 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

hi,


try this


For Each message As DataSet1.messageRow In dt
ifconvert.Tostring(message.to_user)=="" then
'do something
end if
next
End if


Regards
Anil

Thanks & Regards
Anil Kumar Pandey



Author: Hamar Kharshiing    06 Oct 2008Member Level: GoldRating: 1 out of 5     Points: 1

Hi Anil,

It is still givin the same error.



Author: Vivek    10 Oct 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

You need to use DBNulll to check database null values.

first retrieve DataSet values in DataRow

then check

If Not IsDBNull(stringValue) Then

// Your Code
End If

http://msdn.microsoft.com/en-us/library/tckcces5.aspx
http://www.thedatafarm.com/blog/2005/09/09/NullableTypeAndDbNull.aspx



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : treeview with sql oen table only pls code
Previous : i want coding by using SQL Database.
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use