vb.net query

  • Thread starter Thread starter sanjitsil
  • Start date Start date
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)
 
Dim con As New OleDbConnection()
Remove this line in Private Sub Button1_Click
Dim myCommand As New OleDbCommand(cmd, con)
Change this line to reference me.Con which is set in Private Sub Form1_Load

Rob

sanjitsil said:
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)



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
Hi,

I think that your connection string is not properly formatted.
Try with something like:
Data Source="D:\Documents and Settings\Joydip\My Documents\Visual Studio
Projects\WindowsApplication5\Test100.mdb";Password=;Provider="Microsoft.Jet.
OLEDB.4.0";User ID=Admin
Take a look at www.connectionstrings.com for more info on connection
strings.

When do you get the error?
During con.Open() (I guess this one) or cmd.ExecuteNonQuery()?
You might embed the offending method within try/catch block and see what
exception says.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rhand.com

sanjitsil said:
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)



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
Hi,

Where do you get your error? Is it when you call ExecuteNonQuery? If yes,
then which values are you passing to this SQL statement?
 
Back
Top