0
我使用具有10個文本框,1個寄存器按鈕& 1退出按鈕的形式。我已經在MS Access 2007中創建了該數據庫並將該文件保存在桌面上。我已通過「添加新數據源」進行了連接。提供商&路徑是:提供商= Microsoft.Jet.OLEDB.4.0;數據源= C:\用戶\ SIPL \桌面\ Cust_Dtl.mdb。但是,當我點擊註冊了以下錯誤顯示:Vb.net 2010連接與MS Access 2007年
con.Open() - Doesn't have a valid file name.
這裏是我的代碼:
Public Class Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\sipl\Desktop\Cust_Dtl.mdb" & System.IO.Directory.GetCurrentDirectory & "Cust_Dtl.mdb"
Dim insertcmd As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand
Dim con As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection
con.ConnectionString = constring
insertcmd.CommandType = CommandType.Text
insertcmd.CommandText = String.Format("INSERT INTO {0} VALUES ('{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}')", "Table1", TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox7.Text, TextBox8.Text, TextBox9.Text, TextBox10.Text)
insertcmd.Connection = con
con.Open()
Try
insertcmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
con.Close()
End Sub
End Class
請幫助解決這個問題。謝謝。