Click here to Skip to main content
16,021,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 10-Jun-16 7:59am

1 solution

I haven't done Access for quite a while, but check your connection string..
Looking online, I can't find any that start with "Base=". I only see "Provider=". I could be wrong, but it's worth a look.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900