hello everyone ,
I'm trying to insert a data from vb.net to ms access , the application works fine until I click on this button , I get an error on this line "myConnection.ConnectionString = Connstring" saying " ArgumentException was unhandled " !
does anyone care to take a look at my code and share your ideas why it so?
Thanks in advance.
What I have tried:
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form18
Dim Base As String
Dim Dfichier As String
Dim Connstring As String
Dim myConnection As OleDbConnection = New OleDbConnection
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
TextBox1.Clear()
TextBox2.Clear()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Base= "Base = Microsoft.ACE.OLEDB.12.0;Data source="
Dfichier = "C:\Users\Sara\Desktop\Application\Liste des opérateurs.accdb"
Connstring = Base & Dfichier
myConnection.ConnectionString = Connstring
myConnection.Open()
Dim str as String
str = "Insérer votre matricule et zone ([Matricule],[Zone]) Values (?,?)"
Dim cmd As oleDbCommand= New OleDbCommand (str, Myconnection)
cmd.Parameters.Add(New OleDbParameter("Matricule", CType(TextBox2.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Zone", CType(TextBox1.Text, String)))
Try
cmd.ExecuteNonQuery()
cmd.dispose()
myConnection.Close()
TextBox1.Clear()
TextBox2.clear()
Catch ex As Exception
MsgBox(ex.Message)
End try
End Sub
End Class