-1
If conn.State = ConnectionState.Open Then
    conn.Close()
End If
conn.Open()
sql = "SELECT *FROM tbL_books_transactions WHERE transactionID LIKE '%" & TextBox8.Text & "%'"
cmd = New MySqlCommand(sql, conn)

Dim dr As MySqlDataReader

dr = cmd.ExecuteReader
If dr.Read = True Then
    TextBox4.Text = CType(dr("AccessionNo"), String)
    TextBox7.Text = CType(dr("BookTitle"), String)
    TextBox11.Text = CType(dr("DateBorrowed"), String).ToString()
    TextBox3.Text = CType(dr("userID"), String)
    TextBox10.Text = CType(dr("userName"), String)

Else
    MsgBox("No Student Record Exist")

End If
conn.Close()
ElGavilan
  • 6,610
  • 16
  • 27
  • 36
  • Short answer: you can't. It's a null value. What value is coming up as DBNull? All you have here to go on is a code dump. I would just check each value returned in your datareader for null, and if equal to null, return an empty string, otherwise return the contents as a string. – ElGavilan Mar 17 '15 at 15:59
  • what do you mean code dump sir sorry still a newbie in programming :( – JC Tubeo Mar 17 '15 at 16:23
  • you just dumped a bunch of code on the page. – ElGavilan Mar 17 '15 at 16:24
  • i have another question how do you insert a date value from your database to crystal report viewer er cause ived tried to get my date value from database to crystal report but it does not show the date – JC Tubeo Mar 17 '15 at 16:38
  • Post your second question as a separate question on here and it might get answered. Good luck. – ElGavilan Mar 17 '15 at 16:44

1 Answers1

0

This is a simple way to convert a column that contains a null value to something that you are able to work with your textboxes

Dim pos = dr.GetOrdinal("AccessioNo")
TextBox4.Text = if(dr.IsDbNull(pos), string.Empty, dr.GetString(pos))

In this example, first retrieve the ordinal position of the column that you are interested to read. Then use that value to call IsDbNull and put everything inside a ternary operator If the valus is null return an empty string otherwise the content of the field with GetString.

Community
  • 1
  • 1
Steve
  • 213,761
  • 22
  • 232
  • 286