Conversion from type DBNull to type String is not valid!

  • Thread starter Thread starter Glogo
  • Start date Start date
G

Glogo

Guest
Good day MSDN,

I am trying to populate a LIstbox control with values from an Oracle database. But it raises this error every time:

Conversion from type 'DBNull' to type 'String' is not valid! so I handled the nulls from the database level. The error stop popping up but the Listbox control still remain blank.

I used following code:


Try
Dim G_conn As New OracleConnection(Form3.g_JUNODb)
G_conn.Open()

Dim go_cmd As New OracleCommand
go_cmd.Connection = G_conn
go_cmd.CommandText = "select nvl(description,'desc'),nvl(qty,'0'), nvl(selling_price,'1'),nvl(Amount,'1') from RICHCUT.current_sale1"
go_cmd.CommandType = CommandType.Text

Dim G_dataReader As OracleDataReader = go_cmd.ExecuteReader()
While G_dataReader.Read()
ListBox1.Items.Add(CStr(G_dataReader.Item("description")).PadRight(32) + " N" + CStr(G_dataReader.Item("selling_price")) + " (" + CStr(G_dataReader.Item("qty")) + ") N" + CStr(G_dataReader.Item("amount")))

End While

G_dataReader.Dispose()
go_cmd.Dispose()




I have used these lines before and the application is working well. Just copied the same application and this problem started to my greatest suprise! I did not even add the nvl bla bla bla to the original select statement that's working!

SI need urgent help please.


Laborare est Orare...

Continue reading...
 
Back
Top