2014年7月13日 星期日

[RESOLVED] Display data from database to a textbox


in a search page in my asp.net+vb web page.  iam using a code as under but when the field is balnk it gives error.


statustxt.Text = dt.Tables("PERS").Rows(0).Item("OutDetails")


Then i tried this code also 


If dt.Tables("PERS").Rows(0).Item("Courser") Is System.DBNull.Value <> True Then

statustxt.Text = dt.Tables("PERS").Rows(0).Item("OutDetails")

Else

statustxt.Text = ""

End If


but it also gives error as 


Conversion from type 'DBNull' to type 'String' is not valid.






If dt.Tables(0).Rows.Count > 0 Then

Dim outDetails = dt.Tables("PERS").Rows(0)("OutDetails")

If Not outDetails = DBNull.Value And Not outDetails Is Nothing Then


statustxt.Text = dt.Tables("PERS").Rows(0)("OutDetails").ToString()


End If


End If



沒有留言:

張貼留言