Thursday, March 22, 2012

System.NullReferenceException: Object variable or With block variable not set

Please help i am getting the following error:
System.NullReferenceException: Object variable or With block variable not set

on this line.


TextBox1.Text = Trim(Row.Item("eng_lbl"))

I am trying to display the values of a record from the table in 4 text box fields.
I am new to asp.net. Please kindly help.


Dim mydataset As New DataSet
Dim myadapter As New SqlDataAdapter
Dim strId As String = Request.QueryString("lbl_Id")
Dim Row

Dim myCommand As New SqlClient.SqlCommand

Dim sql As String = "select * from tbl_labels where id =" & CInt(strId)

If Not Page.IsPostBack Then
MyCommand = New SqlCommand(sql, MyConnection)

myadapter = New SqlDataAdapter(myCommand)

mydataset.Clear()
myadapter.Fill(mydataset)

If mydataset.Tables(0).Rows.Count > 0 Then
TextBox1.Text = Trim(Row.Item("eng_lbl"))
TextBox2.Text = Trim(Row.Item("esp_lbl"))
TextBox3.Text = Trim(Row.Item("fr_lbl"))
TextBox4.Text = Trim(Row.Item("ger_lbl"))
End If
End If

You're not assign row to anything..

I.E.


Dim Row As DataRow

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

Row = mydataset.Tables(0).Rows(0)

TextBox1.Text = Trim(Row.Item("eng_lbl"))

TextBox2.Text = Trim(Row.Item("esp_lbl"))

TextBox3.Text = Trim(Row.Item("fr_lbl"))

TextBox4.Text = Trim(Row.Item("ger_lbl"))

End If

0 comments:

Post a Comment