 |
|
Error ที่ cmd.ExecuteNonQuery() ใน Update โดยขึ้นว่า No value given for one or more required parameters |
|
 |
|
|
 |
 |
|
น่าจะเป็นที่ชนิดของข้อมูลไม่ตรงกับฐานข้อมูล?
ซึ่งไม่รู้ว่าจะเขียนยังไงถ้าชนิดข้อมูลในฐานข้อมูลเป็นNumber
รายละเอียดของชนิดข้อมูลในฐานข้อมูลมีดังนี้
ID ชนิด Autonumber(ไม่ได้สร้างไว้ในvb)
ID_Product ชนิด Number (ได้สร้างกล่องคำสั่งผสมไว้โดยมีทั้งตัวเลขและข้อความคือ 10 ส้ม 11ฝรั่ง)
out_num ชนิด Number
out_student ชนิด Text
out_store ชนิด Text
out_date ชนิด Date/Time
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
Dim cmd As New OleDbCommand
If Not con.State = ConnectionState.Open Then
'open connection
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
'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.Text & "','" & 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.Value.ToShortDateString & "' " & _
" WHERE ID_Product= '" & Me.semat.Tag & "' "
cmd.ExecuteNonQuery()
End If
'refresh data in list
RefreshData()
'close connection
con.Close()
End Sub
Tag : .NET, Ms Access, VB.NET, VS 2012 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2015-07-18 09:31:14 |
By :
peemes101 |
View :
2053 |
Reply :
8 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา '.........' ออกแล้ว ที่ out_num
แต่ก็ยังขึ้นerror เหมือนเดิม
แต่พอเอาออกที่ID_Product ขึ้นว่า"Syntax error (missing operator) in query expression '101 ส้ม
หมายความว่าอย่างไร
|
ประวัติการแก้ไข 2015-07-18 12:04:09
 |
 |
 |
 |
Date :
2015-07-18 11:57:05 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำไมยังใช้ SQL เดิม ยุละครับไม่เอาที่มันใช้ได้แล้วมาใช้ละ
|
 |
 |
 |
 |
Date :
2015-07-19 09:09:27 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วอะไรคือที่มันใช้ได้ล่ะ
ที่คุณบอกตอนนั้นมันerror ว่า syntax error in UPDATE statement
เพราะในฐานข้อมูลเป็นแบบนี้
ID ชนิด Autonumber(ไม่ได้สร้างไว้ในvb)
ID_Product ชนิด Number (ได้สร้างกล่องคำสั่งผสมไว้โดยมีทั้งตัวเลขและข้อความคือ 10 ส้ม 11ฝรั่ง)
out_num ชนิด Number
out_student ชนิด Text
out_store ชนิด Text
out_date ชนิด Date/Time
โค้ดที่ใช้ล่าสุด
ที่คุณTCmin ให้เอา ' ' ออก
ก็ยังขึ้นว่า no value given for one or more required parameters อยู่ดี
Code (VB.NET)
If Me.semat.Tag Then
'add new
'add data to table
cmd.CommandType = CommandType.Text
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.Value.ToShortDateString & "')"
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 & "' "
|
ประวัติการแก้ไข 2015-07-19 09:49:52 2015-07-19 10:17:07 2015-07-19 10:18:52
 |
 |
 |
 |
Date :
2015-07-19 09:43:59 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แนะนำดังนี้ครับ
Id_Product เปลี่ยนชนิดข้อมูลเป็น Text ซะ ไม่จำเป็นต้องเป็น Number ผสมอย่างที่คุณว่า
out_num= " & txtnum.Text & _ ' ไม่จำเป็นต้องใช้ Me.txtnum. text ก็ได้ครับ
การเก็บวันที่ เพื่อสะดวกและประโยชน์ในการจัดเรียงข้อมูลวันหน้า ควรเก็บแยกเป็น คนละ Field เช่น วันที่ เดือน ปี
พารามีเตอร์ตัวไหนไม่ชัดเจน ในการต่อสตริง พวก ' ... " ... & ลองเปลี่ยนแล้วรันทดสอบดูครับ
ขอให้โปรแกรมของคุณประสพผลสำเร็จครับ
|
 |
 |
 |
 |
Date :
2015-07-19 21:23:09 |
By :
noonkamfunt |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูพวก , ในค่าตัวเลขด้วยครับ หรือไม่ Debug SQL ออกมาดูก็จะรู้แล้วครับ
|
 |
 |
 |
 |
Date :
2015-07-20 10:19:52 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง Update ทีล่ะ field ดูครับ
ไล่ไปเรื่อย ๆ จะได้รู้ว่า Error ที่ตัวไหน
|
 |
 |
 |
 |
Date :
2015-07-20 12:49:11 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|