S
sanjitsil
I am learning VB.NET, trying to insert record in Access Database using
oledbCommand.
I am getting an error Which is typed below during compiling the
programe. I am sending the source code .Please rectify the error and
send me.
ERROR MESSAGE: An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll
source code:
Imports System.Data
Imports System.Data.OleDb
Class Form1
Inherits System.Windows.Forms.Form
Dim con As New OleDbConnection()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
Dim cmd As String
cmd = "Insert Into Emp (ECode,EName) Values('" &
TextBox1.Text & "','" & TextBox2.Text & "')"
Dim myCommand As New OleDbCommand(cmd, con)
myCommand.ExecuteNonQuery()
MsgBox("Record Added")
con.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
con.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Datasource=D:\Documents and
Settings\Joydip\My Documents\Visual Studio
Projects\WindowsApplication5\Test100.mdb"
con.Open()
End Sub
End Class
Database Table Name:Emp
Table Fields:ECode,EName(Both are string type)
oledbCommand.
I am getting an error Which is typed below during compiling the
programe. I am sending the source code .Please rectify the error and
send me.
ERROR MESSAGE: An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll
source code:
Imports System.Data
Imports System.Data.OleDb
Class Form1
Inherits System.Windows.Forms.Form
Dim con As New OleDbConnection()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
Dim cmd As String
cmd = "Insert Into Emp (ECode,EName) Values('" &
TextBox1.Text & "','" & TextBox2.Text & "')"
Dim myCommand As New OleDbCommand(cmd, con)
myCommand.ExecuteNonQuery()
MsgBox("Record Added")
con.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
con.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Datasource=D:\Documents and
Settings\Joydip\My Documents\Visual Studio
Projects\WindowsApplication5\Test100.mdb"
con.Open()
End Sub
End Class
Database Table Name:Emp
Table Fields:ECode,EName(Both are string type)