 |
|
ขึ้นerror tว่า he select statement includes a reserved word or an argument name that is misspelled or missing ตรง da.Fill(dt) ช่วยดูให้หน่อย |
|
 |
|
|
 |
 |
|
-ผิดที่ da.Fill(dt)
-และได้สร้างID ในฐานข้อมูล เป็น autonumber เลยไม่ได้selectมา ไม่ทราบว่าถูกหรือป่าว
และนี้เป็นโค้ดทั้งหมด โดยปุ่มbutton1คือปุ่มเพิ่มข้อมูล ลงในdatagridview
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 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()
Tag : .NET
|
ประวัติการแก้ไข 2015-07-13 08:19:27 2015-07-13 08:21:10 2015-07-13 08:34:55
|
 |
 |
 |
 |
Date :
2015-07-13 08:15:54 |
By :
peemes101 |
View :
1427 |
Reply :
41 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
DateTimePicker1 as [out_date], === Comma เกินมาครับ
|
 |
 |
 |
 |
Date :
2015-07-13 12:46:30 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลังจากแก้ตามที่ทุกคนบอก
ผลคือชี้ที่จุดเดิม ที่ da.Fill(dt)
แต่เปลี่ยนคำerror คือ no value given for one or more required parameters
|
 |
 |
 |
 |
Date :
2015-07-13 19:58:24 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองศึกษาพวก Parameter ก่อนครับ รู้สึกแหม่งๆอ่ะ
|
 |
 |
 |
 |
Date :
2015-07-13 21:19:36 |
By :
Balll2iFFer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอา sql command ที่ได้ไป execute ที่ sql management ครับว่าได้ไหม
|
 |
 |
 |
 |
Date :
2015-07-14 07:39:41 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอดีเป็นมือใหม่
คือฐานข้อมูลที่ใช้เป็น table ของaccess
แล้วทำไมถึงบอกว่า ลองเอา sql command ที่ได้......
หรือว่าทำผิดตั้งแต่ต้น
|
 |
 |
 |
 |
Date :
2015-07-14 08:34:30 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ้าววว ขออภัยครับ ไม่ได้สังเกตุว่าเป็น access
ผมไม่ค่อยได้ใช้ access น่ะครับ ผิดถูกขออภัย
ลองเอา command ที่ได้ไป run ใน access query ดูครับว่ามันทำงานได้หรือปล่าว
|
 |
 |
 |
 |
Date :
2015-07-14 08:43:56 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ทำการแก้ Sql ยังเอามาอัฟใหม่หน่อยครับ
เพราะถ้า SQL
Code (VB.NET)
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)
มันแปลกๆยุนะ
txtnum txtna1 txtna1 DateTimePicker1 มันใช่ตารางใน tb_Out_Product เหรอครับ
ทำไมชื่อมันไม่ยักเหมือน
Code (VB.NET)
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 & "')"
ทั้งๆที่น่าจะเป็นตารางเดียวกัน
ลองใช้แบบนี้ดูครับ
Code (VB.NET)
Dim da As New OleDbDataAdapter("SELECT * FROM tb_Out_Product ORDER BY ID_Product",con)
วิธีการเช็คว่าเกิดจาก SQL ของเรารึป่าวเอาแบบบ้านๆคือให้เริ่มจาก SELECT * FROM ครับ
ถ้าแบบนี้แล้วได้ก็แสดงว่าที่ผ่านมาเป็นที่ syntex SQL ก็ค่อยๆไปศึกษาดู
http://www.w3schools.com/sql/sql_alias.asp
https://www.thaicreate.com/tutorial/sql-alias.html
https://www.thaicreate.com/tutorial/sql.html
แต่ถ้ายัง Error อยู่ก็หาสาเหตุต่อไปแบบบ้านๆตามเคยครับ  
|
 |
 |
 |
 |
Date :
2015-07-14 09:08:08 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือเป็นTable จาก Access
และไม่ได้ดึงID จากtableมา เพราะตั้งเป็นautonumberไว้
ดังนั้น ถ้าเป็นtale จาก access แสดงว่าที่เขียนว่าคือ ผิด ใช่หรือป่าว
และขอดูโค้ดที่เป็นvb+access ของปุ่มเพิ่มข้อมูลลงในdatagridview ที่เป็นตัวอย่างหน่อย
|
 |
 |
 |
 |
Date :
2015-07-14 09:26:12 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ที่ทำน่ะถูกแล้วครับ
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()
Ebd Sub
|
 |
 |
 |
 |
Date :
2015-07-14 09:32:27 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขึ้น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
|
ประวัติการแก้ไข 2015-07-14 11:30:12
 |
 |
 |
 |
Date :
2015-07-14 11:21:25 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทีนี้กดที่ปุ่มเพิ่มแล้ว ไม่มีอะไรเกิดขึ้นเลย
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 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
|
 |
 |
 |
 |
Date :
2015-07-15 09:34:41 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ส่วนท้ายนิดนึงครับ
Catch ex As Exception
msgbox(ex.message)
End Try
บางทีมันอาจ error แต่ไม่บอก
|
 |
 |
 |
 |
Date :
2015-07-15 09:46:23 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค๊ดนี้มันคือไรครับ 
Code (VB.NET)
If Me.semat.Tag & "=" Then
|
 |
 |
 |
 |
Date :
2015-07-15 10:10:28 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ข้อความขึ้นว่า
Systax error (miss operator) in query expression ‘101ส้ม’
โดย semat.seclectitem เป็นcombobox ซึ่งมีitemให้เลือกได้แก่
101ส้ม
102มะละกอ
103 เงาะ
ซึ่งอยากให้โชว์ในการเลือกแบบนี้
ขณะที่ในฐานข้อมูลคอลัมชื่อ สินค้า มีชนิดข้อมูลเป็น 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
|
ประวัติการแก้ไข 2015-07-15 22:41:51 2015-07-15 22:43:11 2015-07-15 22:51:17 2015-07-16 01:13:49
 |
 |
 |
 |
Date :
2015-07-15 22:08:42 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
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 & "')"
|
 |
 |
 |
 |
Date :
2015-07-15 23:19:12 |
By :
Mi |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โอเค ทำตามแล้ว
และขึ้นตอนรันโดยบอกว่า 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
|
ประวัติการแก้ไข 2015-07-16 02:09:15
 |
 |
 |
 |
Date :
2015-07-16 00:49:06 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
" SET ID_Product=" & Me.semat.SelectedItem &
......
.....
" WHERE ID_Product=" & Me.semat.Tag
|
 |
 |
 |
 |
Date :
2015-07-16 08:31:40 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนรัน ขึ้นว่า Systax error (miss operator) in query expression ‘ID_Product=’.
อยู่ดี
|
 |
 |
 |
 |
Date :
2015-07-16 09:17:27 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่อ ขอโทษที
คือตั้งID ในaccessเป็น autonumber ซึ่งเป็นคอลัมที่1
ดังนั้นในUpdateต้องเขียนมั้ย
|
 |
 |
 |
 |
Date :
2015-07-16 09:49:03 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 24 เขียนโดย : peemes101 เมื่อวันที่ 2015-07-16 09:49:03
รายละเอียดของการตอบ ::
มองเห็นแล้วนะครับ   
มันไม่ได้เกี่ยวกับ autonumber โดยตรงครับ
แค่
เมื่อเรา " WHERE ID_Product=" & Me.semat.Tag
เราก็ไม่ควรที่จะ " SET ID_Product=" & Me.semat.SelectedItem
หรือถ้าเราเปลี่ยนเป็นตัวอื่น
Code (VB.NET)
cmd.CommandText = "Update tb_Out_Product " & _
" SET ID_Product=" & Me.semat.SelectedItem &
", out_student='" & Me.txtna1.Text & "'" & _
", out_store='" & Me.txtna2.Text & "'" & _
" ,out_date1='" & Me.txtdate.Value.ToShortDateString & "'" & _
" WHERE out_num=" & Me.txtnum.Text
", out_num='" & Me.txtnum.Text & "'" & _ ก็ต้องหายไปตามระเบียบครับ
เพราะเราระบุอยู่แล้วว่า " WHERE out_num=" & Me.txtnum.Text
ลองแบบนี้ดูครับ
Code (VB.NET)
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_date1='" & Me.txtdate.Value.ToShortDateString & "'" & _
" WHERE ID_Product=" & Me.semat.Tag
End If
cmd.ExecuteNonQuery() 'ย้ายลงมาเพื่อลดการเขียนโค๊ด
ทำบ่อยqจากโค๊ด 5000 บรรทัดอาจจะเหลือแค่ 500 ดูง่ายขึ้นครับ
|
 |
 |
 |
 |
Date :
2015-07-16 10:14:24 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้อ่ะ
ขึ้นว่า syntax error in delete statement
|
 |
 |
 |
 |
Date :
2015-07-16 10:25:49 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พิมผิด
มันขึ้นว่า
syntax error in UPDATE statement
|
 |
 |
 |
 |
Date :
2015-07-16 10:36:51 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ไฟล์ Access ใช่ไหมครับ
เป็นเวอร์ชั่นอะไรเหรอครับ
|
 |
 |
 |
 |
Date :
2015-07-16 10:38:55 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมไม่ค่อยชินกับ access น่ะครับ
แต่อยากให้ลองโหลดโปรแกรมที่เอาไว้ติดต่อกับ Access มาลองใช้ดู
และลองพิมพ์คำสั่ง ทดสอบ ก่อน
แล้วค่อยมาแก้ที่ตัวโปรแกรมอีกที
จะได้รู้ว่า คำสั่งที่เราทำมันใช้ได้หรือปล่าว
ลองโหลดโปรแกรมตัวนี้มาใช้ดูครับ
http://download.cnet.com/SQL-Query-Tool-Using-ODBC/3000-10254_4-10057486.html

|
 |
 |
 |
 |
Date :
2015-07-16 10:51:19 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบคุณ FONFIRE
ใช้access 2007
และตอบคุณ TOR_CHEMISTRY
มันerror ว่า syntax error in UPDATE statement
|
 |
 |
 |
 |
Date :
2015-07-16 11:02:06 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำไมขอดูsql ล่ะ ใช้access 2007
นี้เป็นโค้ดล่าสุด ที่เกิดerror
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 & "')"
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
|
 |
 |
 |
 |
Date :
2015-07-16 11:13:34 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยัง error ว่า syntax error in UPDATE statement อยู่ดี
|
 |
 |
 |
 |
Date :
2015-07-16 11:27:15 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บรรทัดสุดท้าย " WHERE ID_Product=" & Me.semat.Tag น่าจะ " WHERE ID_Product= ' " & Me.semat.Tag & " '; "
|
 |
 |
 |
 |
Date :
2015-07-16 11:33:01 |
By :
Mi |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|