I'm trying to implement a search engine in ASP.NET and VB.net. The search is from a .sdf database. I keep getting a:
System.NullReferenceException: Object reference not set to an instance of an object
The error occurs on the line
myDA.SelectCommand = cm
But I can't point out the source of error since my code looks clean. I will appreciate some Help
Private Sub searchButton_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchButton.Click
registration.Visible = True
con.Open()
cm.Connection = con
cm.CommandText = "SELECT * FROM records WHERE phone = " & phoneTextBox.Text
cm.ExecuteNonQuery()
myDA.SelectCommand = cm
myDA.Fill(myDataSet, "records")
If myDataSet.Tables("records").Rows.Count = 0 Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
Response.Write("Record not Found")
Else
TextBox1.Text = myDataSet.Tables("Records").Rows(0).Item("phone")
TextBox2.Text = myDataSet.Tables("Records").Rows(0).Item("name")
TextBox3.Text = myDataSet.Tables("Records").Rows(0).Item("id")
TextBox4.Text = myDataSet.Tables("Records").Rows(0).Item("pin")
TextBox5.Text = myDataSet.Tables("Records").Rows(0).Item("area")
TextBox6.Text = myDataSet.Tables("Records").Rows(0).Item("subscription")
End If
End Sub