My database has a table called "SerialKey" 3 columns id which is PK Email & Serial.
I have a windows form in VB.NET, the form has 1 label, 1 TextBox, 1 Button, The text in the label displays an email address, this email address will vary. When I click the button on the form I want the database to be searched for the email address and find the serial in the database. I have shown the code below but it gives me an error saying "Object reference not set to an instance of an object" it highlights the line below.
Dim reader As SqlDataReader = command.ExecuteReader()
Can someone help me out here because I'm truly stuck and truly new :) Any help appreciated.
con = New SqlConnection("Data Source= My connection string here; Password='my password here'; ")
cmd.Connection = con
cmd.CommandText = "SELECT Serial FROM SerialKey Where Serial= ?"
cmd.Parameters.AddWithValue("?", LblName.Text)
con.Open()
Dim lrd As SqlDataReader = cmd.ExecuteReader()
While lrd.Read()
'Do something
If lrd.HasRows Then
lrd.Read()
UsersKey.Text = lrd.GetString(1)
TextBox2.Text = lrd.GetString(2)
End If
End While
Catch ex As Exception
MessageBox.Show("Error while retrieving records on table..." & ex.Message, "Load Records")
Finally
con.Close()
End Try