Getting an IO on a null value in a column. Not sure how to handle this in sql. The table is setup where only the key will not accept nulls and the other columns may not be updated. I want to access one column that may not be updated by another process
and place content there or update it.
The initial value is null and causing an exception. Thinking i should test for the null first then act accordingly
I/O Error for on Course Header File =System.IndexOutOfRangeException: HRNotes at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) at _TeacherReqMaint.Page_Load(Object
sender, EventArgs e) in
from.....
IfNot
myreader.IsDBNull(myreader.GetOrdinal("transcriptDeadline"))
Then
I/O Error for on Course Header File =System.IndexOutOfRangeException: HRNotes at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) at _TeacherReqMaint.Page_Load(Object
sender, EventArgs e) in
IndexOutOfRangeException would occur when calling GetOrdinal if there was no column named
transcriptDeadline. Double check your query to make sure that a column "transcriptDeadline" was actually selected.
PS:
Decker Dong - MSFT
IfNot myreader.IsDBNull(myreader("transcriptDeadline")) Then
SqlDataReader.IsDBNull requires an ordinal - not a name.
zeras
Member
9 Points
32 Posts
How to test a reader.item for nullable content
Jan 20, 2013 03:48 PM|LINK
Getting an IO on a null value in a column. Not sure how to handle this in sql. The table is setup where only the key will not accept nulls and the other columns may not be updated. I want to access one column that may not be updated by another process and place content there or update it.
The initial value is null and causing an exception. Thinking i should test for the null first then act accordingly
mbanavige
All-Star
135170 Points
15505 Posts
ASPInsiders
Moderator
MVP
Re: How to test a reader.item for nullable content
Jan 20, 2013 10:43 PM|LINK
you could compare the value you read from the reader to DBNull.Value
http://stackoverflow.com/questions/762861/how-to-check-if-a-datareader-is-null-or-empty
or you could use the reader.IsDBNull method:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.isdbnull.aspx
zeras
Member
9 Points
32 Posts
Re: How to test a reader.item for nullable content
Jan 21, 2013 12:32 AM|LINK
Still getting an exception...
I/O Error for on Course Header File =System.IndexOutOfRangeException: HRNotes at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) at _TeacherReqMaint.Page_Load(Object sender, EventArgs e) in
from.....
If Not myreader.IsDBNull(myreader.GetOrdinal("transcriptDeadline")) Then
txtTranscriptDeadline.Text = myreader.Item("transcriptDeadline")
End If
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to test a reader.item for nullable content
Jan 22, 2013 01:39 AM|LINK
Hi,
"GetOrdinal" will NEVER return you something like a Null value, because it will return you a value of Integer.
And what's more, even if you cannot find the column name, maybe an exception will be thrown out.
So you should check something like this:
If Not myreader.IsDBNull(myreader("transcriptDeadline")) Then
mbanavige
All-Star
135170 Points
15505 Posts
ASPInsiders
Moderator
MVP
Re: How to test a reader.item for nullable content
Jan 22, 2013 02:05 AM|LINK
IndexOutOfRangeException would occur when calling GetOrdinal if there was no column named transcriptDeadline. Double check your query to make sure that a column "transcriptDeadline" was actually selected.
PS:
SqlDataReader.IsDBNull requires an ordinal - not a name.