将数据从VB.NET插入到MS访问 [英] Insert data from VB.NET to MS access
问题描述
大家好,
我正在尝试将数据从vb.net插入ms访问,应用程序正常工作,直到我点击此按钮,我在这行myConnection.ConnectionString = Connstring上输入错误,说ArgumentException未处理!
有没有人关心我的代码并分享你的想法为什么呢?
提前致谢。
我的尝试:
进口系统
进口System.Data
进口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对象,e作为EventArgs)处理Button3.Click
TextBox1.Clear()
TextBox2.Clear()
End Sub
Private Sub Button1_Click(发送者为对象,e为EventArgs)处理Button1.Click
Base =Base = Microsoft.ACE.OLEDB.12.0;数据source =
Dfichier =C:\ Users \Sara\Desktop\Application\Listedesopérateurs.accdb
Connstring = Base& Dfichier
myConnection.ConnectionString = Connstring
myConnection.Open()
Dim str as String
str = Insérervotrematricule et zone([Matricule],[Zone])值(?,?)
Dim cmd as oleDbCommand = New OleDbCommand(str,Myconnection)
cmd.Parameters.Add(新OleDbParameter(Matricule,CType(TextBox2.Text,String)))
cmd.Parameters.Add(新OleDbParameter(Zone) ,CType(TextBox1.Text,String)))
尝试
cmd.ExecuteNonQuery()
cmd.dispose()
myConnection.Close()
TextBox1.Clear()
TextBox2.clear( )
Catch ex As Exception
MsgBox(ex.Message)
结束尝试
End Sub
结束类
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
推荐答案
我还没有完成Access一段时间,但检查你的连接字符串..
在线查看,我找不到以Base =开头的任何内容。我只看到Provider =。我可能错了,但值得一看。
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.
这篇关于将数据从VB.NET插入到MS访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!