Question Locked

problem entering data in access through vb.net

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Dim m_strConn As String = "C:\Documents and Settings\Reflexresources\My Documents\test.mdb"
Dim m_cn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;data source=" & m_strConn & "")

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim cmInsert As OleDbCommand = New OleDbCommand
Dim tempnum As Integer
cmInsert.CommandText = "insert into test1 values('" & TextBox1.Text & "')"
cmInsert.CommandType = CommandType.Text
cmInsert.Connection = m_cn
m_cn.Open()
cmInsert.ExecuteNonQuery()
MsgBox("jai ho")
m_cn.Close()
Catch
Dim ex As SystemException
MessageBox.Show(ex.Message)
End Try

End Sub

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe

Additional information: Object reference not set to an instance of an object.

What to do? Where the problem lies?

1 reply

This discussion is closed to new replies.