p 347 (SafeDataReader):: if(_dataReader.IsDBNull(i)) return char.MinValue; else. return _dataReader.GetChar(i); Since SqlDataReader doesnt have a GetChar method this generates an error http://www.lhotka.net/Article.aspx?id=a51b80c9-dace-4720-8992-576e6cf37df2HOME | SqlDataReader.IsDBNull Method
I think i need to use this to check for null values prior to using the
statement "address.Value = myReader.GetString(5)" otherwise I get the
error "Data is Null. This method or property cannot be called on Null
values"
but am unsure of the code to use it.Please could you give me an
example of the required code to check for null values prior to using
the getstring method
Thanks How To Avoid the Boxing Penalty When You Use the DataReader in Visual :: myReader As SqlDataReader = myCommand.ExecuteReader() Dim str1 As String While To check for NULL, use the IsDBNull method. Back to the top. REFERENCES http://support.microsoft.com/kb/310348HOME | [2005] how to check if data is null in a reader - VBForums:: [2005] how to check if data is null in a reader Visual Basic .NET of the question you will be looking at the SqlDataReader.IsDBNull method. http://www.vbforums.com/showthread.php?p=3120111#post3120111HOME |
I am using VB.Net with SQL Server2000 running on Windows 2000 Server.
Hi,
Can you please clarify what language and what database server are you using?
Thanks
Bio SqlDataReader.GetInt64 Method (System.Data.SqlClient):: Gets the value of the specified column as a 64-bit signed integer. Call IsDBNull to check for null values before calling this method. Platforms http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getint64.aspxHOME |
Dear homebuilder-ga,
You're quite correct in that you need to call this method in order to
check for NULL values before retrieving data through your
SqlDataReader. The specific code you need to do this looks like this:
If (myReader.IsDBNull (5)) Then
' Handle a NULL value, in some appropriate way. Here, I just
substitute
' an empty string for the NULL.
address.Value = ""
Else
' Retrieve the actual value
address.Value = myReader.GetString (5)
End If
An example of using a SqlDataReader to read information from a
database, including this code, can be found by going to:
http://samples.gotdotnet.com/quickstart/howto/
then scrolling down to "Data and ADO.NET", and selecting "Retrieve
data from a SQLServer database".
If this answer isn't quite what you're looking for, please feel free
to request a clarification,
cerebrate-ga
Search strategy:
Personal knowledge.
Traditional University or MLM University? You Choose
15 Questions to Ask Your Software Vendor
|