Hi,

I've problem here. I create 3 check boxlist using vb.net 2.0. One of my check boxlist is uncheck when i try to save in database. when i want to save this using Microsoft access database the error come System.NullReferenceException – “Object reference not set to an instance of an object.

Please help me to encounter this problem.

Member Avatar for iamthwee

Please help me to encounter this problem.

Try running your program again :) I'm sure you'll get the same error.

Try running your program again :) I'm sure you'll get the same error.

Here i 'give my sample coding to help me.

Protected Sub btnaccept_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnaccept.Click
Dim strSQl As String
Dim strluaran, strPersekitaran, strperibadi As String
Dim mycommand As OleDbCommand = New OleDbCommand


conn = New OleDbConnection(connString)
mycommand.Connection = conn

lbldate.Text = Format(Date.Now, "dd-MMM-yyyy")

If IsDBNull(chkluaran.SelectedItem.Text) Then
chkluaran.SelectedItem.Text = ""
End If
If IsDBNull(chkPersekitaran.SelectedItem.Text) Then
chkPersekitaran.SelectedItem.Text = ""
End If
If IsDBNull(chkperibadi.SelectedItem.Text) Then
chkperibadi.SelectedItem.Text = ""
End If
strSQl = " INSERT INTO scan_Cust_result(cust_name,cust_mothername, cust_result_email, cust_result, result_luaran, result_persekitaran, " _
& " result_peribadi, cust_desc, date_created) VALUES " _
& " ('" & lblname.Text & "', '" & lblmothername.Text & "','" & lblemail.Text & "', '" & chkmasalah.SelectedItem.Text & "', " _
& " '" & chkluaran.SelectedItem.Text & "', '" & chkPersekitaran.SelectedItem.Text & "', '" & chkperibadi.SelectedItem.Text & "', " _
& " '" & txtdesc.Text & "', '" & lbldate.Text & "')"
Try
conn.Open()
mycommand.ExecuteNonQuery()
conn.Close()
Response.Write("Your Results are Successfully Saved.")
Catch SQLexc As OleDbException
Response.Write("Insert Failed. Error Details are: " & SQLexc.ToString())
End Try

End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.