我正在研究班加罗尔大学规定的一个项目。我使用 vb.net 2008 作为前端,使用 Ms Access 2007 作为后端。当我尝试运行该程序时,我收到一个错误,因为ConnectionString 属性尚未初始化。
这是我使用的代码
private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add.Click
Dim con As New OleDb.OleDbConnection
Dim cmd As New OleDb.OleDbCommand
Dim dbProvider As String
Dim dbSource As String
dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
dbSource = "DataSource=C:\My Project\project.mdb"
con.ConnectionString = dbProvider & dbSource
con = New OleDb.OleDbConnection
con.Open()
cmd.Connection = con
cmd.CommandText = "Insert Into Application(appno, mname, age, gender, height, weight, address, purpose, bmi, mailid, phoneno, paymnet)" & _
"Values('" & Me.appno.Text & "', '" & Me.mname.Text & "', '" & Me.age.Text & "', '" & Me.gender.Text & "', '" & _
Me.mheight.Text & "', '" & Me.weight.Text & "', '" & Me.address.Text & "', '" & Me.purpose.Text & "', '" & _
Me.bmi.Text & "', '" & Me.mailid.Text & "', '" & Me.phoneno.Text & "', '" & Me.payment.Text & "')"
cmd.ExecuteNonQuery()
con.Close()
End Sub