挿入ステートメントに何が欠けていますか? 完全なコードはここにあります。新しいフィールド値を .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 & "' )"