Hi everyone, I'm having this problem with my code and cannot seem to get past it although it was working fine before.
The error is "An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object."
The code is:
Private Sub btneditstudent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneditstudent.Click
Dim sqlx As OleDbCommand = New OleDbCommand
Dim con As New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source = Decisionmaths.mdb")
Dim xyz As String
xyz = Mid(lstboxstudents.SelectedItem, 1, 8)
sqlx.CommandText = ("SELECT * FROM Student WHERE StudentNumber = " & xyz)
sqlx.Connection = con
con.Open()
Dim rdr As OleDbDataReader = sqlx.ExecuteReader()
If rdr.Read = True Then
frmviewsdets.txtsnumber.Text = rdr("StudentNumber")
frmviewsdets.txtfname.Text = rdr("SFirstName")
frmviewsdets.txtsname.Text = rdr("SSurname")
frmviewsdets.txttgroup.Text = rdr("TutorGroup")
frmviewsdets.txtascore.Text = rdr("ALISScore")
frmviewsdets.txtgcsemath.Text = rdr("GCSEMathsGrade")
frmviewsdets.txtattend.Text = rdr("Attendance")
frmviewsdets.txtclassid.Text = rdr("ClassID")
frmviewsdets.txtpword.Text = rdr("SPassword")
End If
con.Close()
frmviewsdets.btndeletesdets.Hide()
frmviewsdets.btnaddsdets.Hide()
frmviewsdets.btnviewsdets.Hide()
frmviewsdets.Show()
Me.Hide()
End Sub
EXTRA INFO IF NEEDED: I am trying to get information to be pulled out of a database and show in text boxes on another form (frmviewsdets). The error occurs when it gets to the line frmviewsdets.txtsnumber.Text = rdr("StudentNumber") and even when a breakpoint is applied there it just moves on to the next and so on.
I have tried to show frmviewsdets before I pull the data out of the database beut I get the same message. Any help would be appreciated, thank you!