Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help!!! Stuck on a null value from table. 1

Status
Not open for further replies.

simian101

MIS
Nov 16, 2007
113
US
I have a null value in a table. When I read it, it automatically fails. I have tried several things I found on the net but nothing works. As long as it is a string it works.

Any suggestions....

Dim mySelectQuery As String = "select * from dbo.znid where left(znidadd,7)= '" & ComboBox1.Text & "'"
Dim myConnection As New OdbcConnection(myConnString)
Dim myCommand As New OdbcCommand(mySelectQuery, myConnection)

myConnection.Open()
Dim myReader As OdbcDataReader = myCommand.ExecuteReader()
Try
While myReader.Read()
'****code fails here******
Console.WriteLine(myReader.GetString(1))
End While
Finally

Thanks

Simi

 
Try IsDBNull.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Or just append a blank space to your writeline, after the db value...

Console.WriteLine(myReader.GetString(1) & "")
 
I have tried every example of IsDBNull. that I can find.

I also tried the
Console.WriteLine(myReader.GetString(1) & ""))
and it goes staight to Finally in my try.

Thanks

Simi
 
Have you tried?

[tt]
If IsDBNull(dr.GetValue(1)) Then
MessageBox.Show("Null value")
Else
MessageBox.Show(dr.GetValue(1).ToString)
End If
[/tt]


Hope this helps.

[vampire][bat]
 
yep... I tried your exact code. No luck.

Stepping thru... Once it hits

If IsDBNull(myReader.GetString(1)) Then

It goes staight to my Try's finally.

Simi

 
I was suggesting using .GetValue, NOT .GetString

As .GetValue returns an Object as opposed to a String, there should be no problems with Nulls

[vampire][bat]
 
One other problem I see in your code block is that your TRY...CATCH block doesn't have a CATCH clause (or an END TRY). Which is why when it fails, it goes directly to your Try's finally. Also, if you don't have any code in your Finally block, you don't need to include the finally block.

Dim mySelectQuery As String = "select * from dbo.znid where left(znidadd,7)= '" & ComboBox1.Text & "'"
Dim myConnection As New OdbcConnection(myConnString)
Dim myCommand As New OdbcCommand(mySelectQuery, myConnection)

myConnection.Open()
Dim myReader As OdbcDataReader = myCommand.ExecuteReader()
Try
While myReader.Read()
'****code fails here******
Console.WriteLine(myReader.GetString(1))
End While
Catch ex as Exception
Messagebox.Show("ERROR: " & ex.ToString)
End Try



 
earthandfire you are a genius.... The small things we overlook... That cost us about 4 hours. :(

Have a Star.

rjoubert, noted... Thanks also

Thanks

MJ

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top