Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I'm getting an intermittent error and I have no idea what is causing it. Basically, I am getting info from a database (via Stored Procedure) and putting it into a DataSet. Most of the time it works just fine. Occasionally though, one of the Columns from the database does not seem to be making it into the DataSet. The columns that I'm asking for are the same every time (there is no code selecting columns based on user choices or application conditions). Can anyone think of a reason why I would occasionally not get a certain column? Here is the code I'm using to fill the dataset...

 

Try
'Connect to the database
cn = New SqlConnection(cnStr)
cn.Open()
'Set the sql command's attributes
cmd = New SqlCommand("spGetCallList", cn)
cmd.CommandType = CommandType.StoredProcedure

'Retrieve the data from the database
da = New SqlDataAdapter(cmd)
da.Fill(ds)

...
            
'Here is where I'm requesting the data from the column that is
'that is occasionally not showing up
Dim liText As String = r.Item("CallListDesc").ToString

...

Catch ex As Exception
'Inform the user of the error
DisplayAlert(ex.Message)
End Try

 

To make matters worse, it is also happening in a completely unrelated method as well (exact same behavior but the errors do not happen at the exact same time...). Does anyone have any ideas?

Edited by Mothra
Being smarter than you look is always better than looking smarter than you are.
  • *Experts*
Posted

Maybe compare r.Item("CallListDesc") to System.DBNull.Value? I don't think you can use .ToString() on a column that contains DBNull (the equivalent of the database's null).

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
No, I was taking care of the nulls in the stored procedure (ISNULL()). As it turns out, it's not my code after all. The SQL Server was having troubles so...thanks though. I do appreciate the help.
Being smarter than you look is always better than looking smarter than you are.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...