插入语句中缺少什么?完整的代码现在在这里。我无法将新字段值添加到 .mdb 文件。开发这个应用程序花了 3 天时间,现在它没有运行。
插入语句中缺少什么?完整的代码现在在这里。我无法将新字段值添加到 .mdb 文件。开发这个应用程序花了 3 天时间,现在它没有运行。
Public Class client
Dim cnn As New OleDb.OleDbConnection
Private Sub reloaddata()
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("select * from clientsData", cnn)
Dim dt As New DataTable
da.Fill(dt)
Me.cview.DataSource = dt
cnn.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
display.Hide()
cnn = New OleDb.OleDbConnection
cnn.ConnectionString = "provider= microsoft.jet.oledb.4.0; data source=" & Application.StartupPath & "\clients.mdb"
Me.reloaddata()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
display.Show()
End Sub
Private Sub cview_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles cview.CellClick
If cnn.State = ConnectionState.Closed Then
cnn.Open()
End If
Dim i As Integer
i = cview.CurrentRow.Index
If cview.CurrentCell.Value Is Nothing Then
MsgBox("Empty Field")
Else
view.lbl1.Text = cview.Item(0, i).Value.ToString
view.lbl2.Text = cview.Item(1, i).Value.ToString
view.lbl3.Text = cview.Item(2, i).Value.ToString
view.lbl4.Text = cview.Item(3, i).Value.ToString
view.lbl5.Text = cview.Item(4, i).Value.ToString
view.lbl6.Text = cview.Item(5, i).Value.ToString
view.lbl7.Text = cview.Item(6, i).Value.ToString
view.lbl8.Text = cview.Item(11, i).Value.ToString
view.lbl9.Text = cview.Item(12, i).Value.ToString
view.lbl10.Text = cview.Item(7, i).Value.ToString
view.lbl11.Text = cview.Item(8, i).Value.ToString
view.lbl12.Text = cview.Item(9, i).Value.ToString
view.lbl13.Text = cview.Item(10, i).Value.ToString
view.lbl14.Text = cview.Item(13, i).Value.ToString
view.Show()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
cmd.CommandText = "insert into clientsdata(ID,Client,Project,Domain,Hosting,bulk sms,maintenance,Order date,amount,last billing,next billing,username,password,due amount) VALUES ('" & Me.cid.Text & "','" & Me.cname.Text & "','" & Me.cproj.Text & "','" & Me.cdmn.Text & "','" & Me.chost.Text & "','" & Me.csms.Text & "','" & Me.cmain.Text & "','" & Me.codt.Text & "','" & Me.camnt.Text & "','" & Me.cldt.Text & "','" & Me.cndt.Text & "','" & Me.cuid.Text & "','" & Me.cpass.Text & "','" & Me.cdue.Text & "' )"
cmd.ExecuteNonQuery()
Me.reloaddata()
cnn.Close()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
cid.Text = "cid"
cname.Text = "cname"
cproj.Text = "cpro"
cdmn.Text = "domain"
chost.Text = "chost"
csms.Text = "sms"
cmain.Text = "main"
codt.Text = "codt"
camnt.Text = "mount"
cldt.Text = "last"
cndt.Text = "next"
cdue.Text = "due"
cuid.Text = "uid"
cpass.Text = "pass"
End Sub
结束类
好的问题解决了!!我刚刚在字段中添加了 [ ]。
来源:(VB.NET)INSERT INTO 语句中的语法错误 - MICROSOFT JET DATABASE ENGINE
cmd.CommandText = "insert into clientsdata([ID],[Client],[Project],[Domain],[Hosting],[bulk sms],[maintenance],[Order date],[amount],[last billing],[next billing],[username],[password],[due amount]) VALUES (" & Me.cid.Text & ",'" & Me.cname.Text & "','" & Me.cproj.Text & "','" & Me.cdmn.Text & "','" & Me.chost.Text & "','" & Me.csms.Text & "','" & Me.cmain.Text & "','" & Me.codt.Text & "','" & Me.camnt.Text & "','" & Me.cldt.Text & "','" & Me.cndt.Text & "','" & Me.cuid.Text & "','" & Me.cpass.Text & "','" & Me.cdue.Text & "' )"