HOME > .NET Framework > Forum > ขึ้นerror tว่า he select statement includes a reserved word or an argument name that is misspelled or missing ตรง da.Fill(dt) ช่วยดูให้หน่อย
ขึ้นerror tว่า he select statement includes a reserved word or an argument name that is misspelled or missing ตรง da.Fill(dt) ช่วยดูให้หน่อย
Private Sub RefreshData()
If Not con.State = ConnectionState.Open Then
'open connection
con.Open()
End If
Dim da As New OleDbDataAdapter("SELECT selectitemmat as [ID_Product], " & _
"txtnum as [out_num],txtna1 as [out_student],txtna2 as [out_store]," & _
"DateTimePicker1 as [out_date]," &
"FROM tb_Out_Product ORDER BY selectitemmat",con)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
'offer data in data table into datagridview
Me.DataGridView1.DataSource = dt
'close connection
con.Close()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles add.Click
Dim cmd As New OleDbCommand
If Not con.State = ConnectionState.Open Then
'open connection if it is not yet open
con.Open()
End If
cmd.Connection = con
'check whether add new or update
If Me.txtmat.Tag & "=" Then
'add new
'add data to table
cmd.CommandText = " INSERT INTO tb_Out_Product(ID_Product, out_num, out_student, out_store, out_date)" & _
" VALUES (" & Me.selectitemmat.SelectedItem & ",'" & Me.txtnum.Text & "','" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & _
Me.DateTimePicker1.Text & "')"
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery()
Else
'update data in table
cmd.CommandText = "Update tb_Out_Product" & _
"SET ID_Product" & Me.selectitemmat.SelectedItem & _
",out_num" & Me.txtnum.Text & "'" & _
",out_student" & Me.txtna1.Text & "'" & _
",out_store" & Me.txtna2.Text & "'" & _
",out_date1" & Me.DateTimePicker1.Text & "'" & _
"WHERE ID_Product=" & Me.txtmat.Tag
cmd.ExecuteNonQuery()
End If
'refresh data in list
RefreshData()
'clear form
Me.Button6.PerformClick()
'close connection
con.Close()
Dim da As New OleDbDataAdapter("SELECT selectitemmat as [ID_Product], " & _
"txtnum as [out_num],txtna1 as [out_student],txtna2 as [out_store]," & _
"DateTimePicker1 as [out_date]," &
"FROM tb_Out_Product ORDER BY selectitemmat",con)
Private Sub RefreshData()
If Not con.State = ConnectionState.Open Then
'open connection
con.Open()
End If
Dim da As New OleDbDataAdapter("SELECT * FROM tb_Out_Product ORDER BY ID_Product",con)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
'offer data in data table into datagridview
Me.DataGridView1.DataSource = dt
'close connection
con.Close()
Ebd Sub
ขึ้นerrorที่ cmd.ExecuteNonQuery() แจ้งว่า Syntax error in UPDATE statement.
Code (VB.NET)
Private Sub RefreshData()
If Not con.State = ConnectionState.Open Then
'open connection
con.Open()
End If
Dim da As New OleDbDataAdapter("SELECT * FROM tb_Out_Product ORDER BY ID_Product", con)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
'offer data in data table into datagridview
Me.DataGridView1.DataSource = dt
'close connection
con.Close()
End Sub
Dim cmd As New OleDbCommand
If Not con.State = ConnectionState.Open Then
'open connection if it is not yet open
con.Open()
End If
cmd.Connection = con
If Not con.State = ConnectionState.Open Then
'open connection if it is not yet open
con.Open()
End If
cmd.Connection = con
'check whether add new or update
If Me.semat.Tag Then
'add new
'add data to table
cmd.CommandText = " INSERT INTO tb_Out_Product(ID_Product, out_num, out_student, out_store, out_date)" & _
" VALUES (" & Me.semat.SelectedItem & ",'" & Me.txtnum.Text & "','" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & _
Me.txtdate.Text & "')"
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery()
Else
'update data in table
cmd.CommandText = "Update tb_Out_Product" & _
"SET ID_Product" & Me.semat.SelectedItem & _
",out_num" & Me.txtnum.Text & "'" & _
",out_student" & Me.txtna1.Text & "'" & _
",out_store" & Me.txtna2.Text & "'" & _
",out_date1" & Me.txtdate.Text & "'" & _
"WHERE ID_Product=" & Me.semat.Tag
cmd.ExecuteNonQuery()
End If
'close connection
con.Close()
Endsub
Private Sub RefreshData()
If Not con.State = ConnectionState.Open Then
'open connection
con.Open()
End If
Dim da As New OleDbDataAdapter("SELECT semet as [ID_Product], " & _
"txtnum as [out_num], txtna1 as [out_student], txtna2 as [out_store]," & _
"txtdate as [out_date]" &
"FROM tb_Out_Product ORDER BY semat ", con)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
'offer data in data table into datagridview
Me.DataGridView1.DataSource = dt
'close connection
con.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles add.Click
Try
Dim cmd As New OleDbCommand
If Not con.State = ConnectionState.Open Then
'open connection if it is not yet open
con.Open()
End If
cmd.Connection = con
If semat.SelectedItem = "" Then
MessageBox.Show("กรุณาเลือกสินค้า")
Me.semat.Focus()
Exit Sub
End If
If txtnum.Text = "" Then
MessageBox.Show("กรุณากรอกจำนวน")
Me.txtnum.Focus()
Exit Sub
End If
If txtna1.Text = "" Then
MessageBox.Show("กรุณากรอกชื่อผู้ส่ง")
Me.txtna1.Focus()
Exit Sub
End If
If txtna2.Text = "" Then
MessageBox.Show("กรุณากรอกชื่อผู้รับ")
Me.txtna2.Focus()
Exit Sub
End If If txtna2.Text = "" Then
MessageBox.Show("กรุณาเลือกวันเดือนปี")
Me.txtna2.Focus()
Exit Sub
End If
'check whether add new or update
If Me.semat.Tag & "=" Then
'add new
'add data to table
cmd.CommandText = " INSERT INTO tb_Out_Product(ID_Product, out_num, out_student, out_store, out_date)" & _
" VALUES (" & Me.semat.SelectedItem & ",'" & Me.txtnum.Text & "','" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & _
Me.txtdate.Text & "')"
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery()
Else
'update data in table
cmd.CommandText = "Update tb_Out_Product" & _
"SET ID_Product" & Me.semat.SelectedItem & _
",out_num='" & Me.txtnum.Text & "'" & _
",out_student='" & Me.txtna1.Text & "'" & _
",out_num='" & "'" & _
",out_date1='" & Me.txtdate.Text & "'" & _
"WHERE ID_Product='" & Me.semat.Tag
cmd.ExecuteNonQuery()
End If
Catch ex As Exception
End Try
End Sub
ขณะที่ในฐานข้อมูลคอลัมชื่อ สินค้า มีชนิดข้อมูลเป็น Number
ดังนั้นควรเปลี่ยนเป็นอย่างไร
Code (VB.NET)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles add.Click
Try
Dim cmd As New OleDbCommand
If Not con.State = ConnectionState.Open Then
'open connection if it is not yet open
con.Open()
End If
cmd.Connection = con
If semat.SelectedItem = "" Then
MessageBox.Show("กรุณาเลือกสินค้า")
Me.semat.Focus()
Exit Sub
End If
If txtnum.Text = "" Then
MessageBox.Show("กรุณากรอกจำนวน")
Me.txtnum.Focus()
Exit Sub
End If
If txtna1.Text = "" Then
MessageBox.Show("กรุณากรอกชื่อ")
Me.txtna1.Focus()
Exit Sub
End If
If txtna2.Text = "" Then
MessageBox.Show("กรุณากรอกชื่อ")
Me.txtna2.Focus()
Exit Sub
End If
If txtdate.Value.ToShortDateString = "" Then
MessageBox.Show("กรุณาเลือก")
Me.txtdate.Focus()
Exit Sub
End If
cmd.Connection = con
'check whether add new or update
If Me.semat.Tag Then
'add new
'add data to table
cmd.CommandText = " INSERT INTO tb_Out_Product(ID,ID_Product, out_num, out_student, out_store, out_date)" & _
" VALUES (" & Me.semat.SelectedItem & ",'" & Me.txtnum.Text & "','" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & _
Me.txtdate.Value.ToShortDateString & "')"
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery()
Else
'update data in table
cmd.CommandText = "Update tb_Out_Product " & _
" SET ID_Product='" & Me.semat.SelectedItem & "'" & _
", out_num='" & Me.txtnum.Text & "'" & _
", out_student='" & Me.txtna1.Text & "'" & _
", out_store='" & Me.txtna2.Text & "'" & _
" ,out_date1='" & Me.txtdate.Value.ToShortDateString & "'" & _
" WHERE ID_Product=" & Me.semat.Tag
cmd.ExecuteNonQuery()
End If
RefreshData()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
และขึ้นตอนรันโดยบอกว่า Systax error (miss operator) in query expression ‘ID_Product=’.
Code (VB.NET)
Try
Dim cmd As New OleDbCommand
If Not con.State = ConnectionState.Open Then
'open connection if it is not yet open
con.Open()
End If
cmd.Connection = con
If semat.SelectedItem = "" Then
MessageBox.Show("กรุณาเลือกวัสดุฝึก")
Me.semat.Focus()
Exit Sub
End If
If txtnum.Text = "" Then
MessageBox.Show("กรุณากรอกจำนวนที่เบิก")
Me.txtnum.Focus()
Exit Sub
End If
If txtna1.Text = "" Then
MessageBox.Show("กรุณากรอกชื่อผู้เบิก")
Me.txtna1.Focus()
Exit Sub
End If
If txtna2.Text = "" Then
MessageBox.Show("กรุณากรอกชื่อผู้จ่าย")
Me.txtna2.Focus()
Exit Sub
End If
If txtdate.Value.ToShortDateString = "" Then
MessageBox.Show("กรุณาเลือกวันเดือนปี")
Me.txtdate.Focus()
Exit Sub
End If
cmd.Connection = con
'check whether add new or update
If Me.semat.Tag Then
'add new
'add data to table
cmd.CommandText = " INSERT INTO tb_Out_Product(ID,ID_Product, out_num, out_student, out_store, out_date)" & _
" VALUES ('" & Me.semat.SelectedItem & "','" & Me.txtnum.Text & "','" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & _
Me.txtdate.Value.ToShortDateString & "')"
cmd.ExecuteNonQuery()
Else
'update data in tab
cmd.CommandText = "Update tb_Out_Product " & _
" SET ID_Product=" & Me.semat.SelectedItem &
", out_num='" & Me.txtnum.Text & "'" & _
", out_student='" & Me.txtna1.Text & "'" & _
", out_store='" & Me.txtna2.Text & "'" & _
" ,out_date1='" & Me.txtdate.Value.ToShortDateString & "'" & _
" WHERE ID_Product=" & Me.semat.Tag
cmd.ExecuteNonQuery()
End If
RefreshData()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles add.Click
Try
Dim cmd As New OleDbCommand
If Not con.State = ConnectionState.Open Then
'open connection if it is not yet open
con.Open()
End If
cmd.Connection = con
If semat.SelectedItem = "" Then
MessageBox.Show("กรุณาเลือกวัสดุฝึก")
Me.semat.Focus()
Exit Sub
End If
If txtnum.Text = "" Then
MessageBox.Show("กรุณากรอกจำนวนที่เบิก")
Me.txtnum.Focus()
Exit Sub
End If
If txtna1.Text = "" Then
MessageBox.Show("กรุณากรอกชื่อผู้เบิก")
Me.txtna1.Focus()
Exit Sub
End If
If txtna2.Text = "" Then
MessageBox.Show("กรุณากรอกชื่อผู้จ่าย")
Me.txtna2.Focus()
Exit Sub
End If
If txtdate.Value.ToShortDateString = "" Then
MessageBox.Show("กรุณาเลือกวันเดือนปี")
Me.txtdate.Focus()
Exit Sub
End If
cmd.Connection = con
'check whether add new or update
If Me.semat.Tag Then
'add new
'add data to table
cmd.CommandText = " INSERT INTO tb_Out_Product(ID,ID_Product, out_num, out_student, out_store, out_date)" & _
" VALUES ('" & Me.semat.SelectedItem & "','" & Me.txtnum.Text & "','" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & _
Me.txtdate.Value.ToShortDateString & "')"
Else
'update data in tab
cmd.CommandText = "Update tb_Out_Product " & _
", out_num='" & Me.txtnum.Text & "'" & _
", out_student='" & Me.txtna1.Text & "'" & _
", out_store='" & Me.txtna2.Text & "'" & _
" ,out_date='" & Me.txtdate.Value.ToShortDateString & "'" & _
" WHERE ID_Product=" & Me.semat.Tag
End If
cmd.ExecuteNonQuery()
RefreshData()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub