 |
|
ได้ทำปุ่มแก้ไข แต่มันขึ้นerrorว่า "Syntax error (missing operator) in query expression '101 ส้ม’. ควรแก้อย่างไรดี |
|
 |
|
|
 |
 |
|
ก็ยังerror ว่า "Syntax error (missing operator) in query expression '101 ส้ม’.
อันนี้เป็นของ
Code (VB.NET)
INSERT INTO Tb_History(His_product, His_number, His_student, His_teacher, His_date, His_time)" & _
" VALUES ('" & Me.semat.Text & "'," & Me.txtnum.Text & ",'" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & Me.txtdate.Text & "','" & _
Me.txttime.Text & "')"
ปล.ไม่ทราบว่าใช่ค่า sql ที่คุณต้องการหรือป่าว
|
 |
 |
 |
 |
Date :
2015-09-19 14:20:26 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
data type ดูยังครับ
อย่าง His_date, His_time ต้อง convert ก่อน นี้ๆๆๆ อ่าครับ
|
 |
 |
 |
 |
Date :
2015-09-19 14:27:11 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ในความคิดเห็นที่2 เอามาจากปุ่มadd ซึ่งสามารถใช้งานได้ปกติ
แล้วที่คุณTOR_CHEMISTRYบอก ต้องมีการเขียนประมาณไหน ในการconvert
|
 |
 |
 |
 |
Date :
2015-09-19 16:00:20 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช่แบบนี้
Code (VB.NET)
Me.txtnum.Text = dt.Rows(0).Item("His_number")
Dim j As Integer
j = Int(dt.Rows(0).Item("His_number"))
หรือ
Code (VB.NET)
Me.txtnum.Text = Convert.ToInt32(dt.Rows(0).Item("His_number"))
Me.txtdate.Text = Convert.ToDateTime(dt.Rows(0).Item("His_date"))
คือไอ Me.semat.Text เป็นcomboboxให้เลือก
ที่ไม่มีID เพราะได้ตั้งเป็นAutonumber ในdatabaseไว้
มันก็ยังขึ้น error ว่า "Syntax error (missing operator) in query expression '101 ส้ม’.เหมือนเดิมอยู่ดีอ่ะ
แต่อยากถามอีกอย่างว่า มันไม่ได้บอกว่าเป็นที่ data type เลย ดังนั้นอาจจะไม่เกี่ยวว่าต้อง convertหรือป่าว
|
ประวัติการแก้ไข 2015-09-19 22:41:19 2015-09-19 22:43:00 2015-09-19 22:53:33 2015-09-19 23:12:00 2015-09-20 03:25:35
 |
 |
 |
 |
Date :
2015-09-19 22:33:37 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 6 เขียนโดย : peemes101 เมื่อวันที่ 2015-09-19 22:33:37
รายละเอียดของการตอบ ::
Code (VB.NET)
Me.txtnum.Text = Convert.ToInt32(dt.Rows(0).Item("His_number"))
Me.txtdate.Text = Convert.ToDateTime(dt.Rows(0).Item("His_date"))
ผลที่ด้ออกมามันก็เปน string ยุดีนี่ครับ
ที่ผมหมายถึงคือ
Code (VB.NET)
INSERT INTO Tb_History(His_product, His_number, His_student, His_teacher, His_date, His_time)" & _
" VALUES ('" & Me.semat.Text & "'," & Convert.ToInt32(Me.txtnum).Text & ",'" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & Me.txtdate.Text & "','" & _
Convert.ToDateTime(Me.txttime.Text) & "')"
ต่างหาก
ทีนี้ก็เชคให้ครบว่ามีไรบ้างที่ต้องเปลี่ยน
วิT ง่ายที่จะรู้ด้คือลอง inert โดยใส่ค่าเลยครับ
อย่าง
Code (VB.NET)
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway')
ว่า Error ไม๊ ครับผมใช้วิTนี้เชค sql systex
แต่ที่ดีสุดผมใช้ data wizard เช็คดู
ช่วยให้เขียนเรวขึ้น
http://www.homeandlearn.co.uk/NET/nets12p2ed.html
http://
|
 |
 |
 |
 |
Date :
2015-09-20 07:37:14 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ชักจะเร่มงง
ตกลงที่ Error ใช่
Code (VB.NET)
INSERT INTO Tb_History(His_product, His_number, His_student, His_teacher, His_date, His_time)" & _
" VALUES ('" & Me.semat.Text & "'," & Me.txtnum.Text & ",'" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & Me.txtdate.Text & "','" & _
Me.txttime.Text & "')"
หรือ
Code (VB.NET)
Dim da As New OleDbDataAdapter("SELECT * FROM Tb_History WHERE His_product = '" & intsi & "' ", con)
ครับ
|
 |
 |
 |
 |
Date :
2015-09-20 07:44:51 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
11.Dim da As New OleDbDataAdapter("SELECT * FROM Tb_History " & _
12." WHERE His_product = '" & intsi & "' ", con)
ลองแก้เป็น
Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Tb_History " & _
" WHERE His_product = '" & intsi & "' ", con)
|
 |
 |
 |
 |
Date :
2015-09-20 09:07:12 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
่ตอบคุณ TOR_CHEMISTRY
มันerror ในขณะที่รันโปรแกรม คือตอนกด อัพเดทข้อมูล มันก็ขึ้นerrorว่า "Syntax error (missing operator) in query expression '101 ส้ม’.
โค้ดที่ใช้คือ บนสุด
ตอบคุณ NewbieXYZ
มันก็ยังerrorเหมือนเดิม
|
 |
 |
 |
 |
Date :
2015-09-20 15:59:03 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันerrorที่ da.Fill(dt) โดยขึ้นว่า "Syntax error (missing operator) in query expression '101 ส้ม’.
|
 |
 |
 |
 |
Date :
2015-09-20 21:37:12 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัวอย่างการใช้ OleDbDataAdapter Datatable() ลองประยุกต์เอานะครับ
Code (VB.NET)
Dim custDA As OleDbDataAdapter = New OleDbDataAdapter()
Dim custDS As DataSet = New DataSet
Dim custTable As DataTable = New DataTable("Customers")
custTable.Columns.Add("CustomerID", Type.GetType("System.String"))
custTable.Columns.Add("CompanyName", Type.GetType("System.String"))
custDS.Tables.Add(custTable)
'Use ADO objects from ADO library (msado15.dll) imported
' as.NET library ADODB.dll using TlbImp.exe
Dim adoConn As ADODB.Connection = New ADODB.Connection()
Dim adoRS As ADODB.Recordset = New ADODB.Recordset()
adoConn.Open("Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;", "", "", -1)
adoRS.Open("SELECT CustomerID, CompanyName FROM Customers", adoConn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 1)
custDA.Fill(custTable, adoRS)
adoRS.Close()
adoConn.Close()
จากตัวอย่าง ลองย้าย statement ใน da มาไว้ใน dt แทนครับ
Dim dt as Datatable = new Datatable( statment );
ผมลองเสริชหาดูหลายตัวอย่าง ไม่เห็นตัวอย่างไหนใส่ statement ใน OleDbDataAdapter อะครับ
เห็นแต่ใส่ใน DataTable
Code (VB.NET)
Dim da As OleDbDataAdapter = New OleDbDataAdapter()
Dim dt As DataTable = New DataTable("SELECT * FROM Tb_History " & _
" WHERE His_product = '" & intsi & "' ")
da.Fill(dt, con)
|
ประวัติการแก้ไข 2015-09-21 06:40:47 2015-09-21 06:47:45
 |
 |
 |
 |
Date :
2015-09-21 06:30:14 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูข้อมูลใน His_product หน่อยครับว่ามีไรบ้าง
ตัวนี้เป็น DataTable ที่ผมใช้อยู่ประจำ
Code (VB.NET)
Public Function GetTableForm(connectionString As String, _SQL As String) As System.Data.DataTable
Dim ds As New System.Data.DataSet()
Dim conn1 As New System.Data.OleDb.OleDbConnection(connectionString)
conn1.Open()
Dim adapter1 As New System.Data.OleDb.OleDbDataAdapter(_SQL, conn1)
adapter1.Fill(ds)
Return ds.Tables(0)
End Function
Code (VB.NET)
Dim dt As System.Data.DataTable = GetTableForm("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=X:\DATA\CONTACT.mdb;Persist Security Info=True;Jet OLEDB:Database Password=4410210091", "SELECT Name_1 FROM tblContact_Companyslist WHERE (Com_ID like '%001%')")
|
 |
 |
 |
 |
Date :
2015-09-21 08:14:21 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบคุณ NewbieXYZ
มัน error ที่da.Fill(dt, con)โดยขึ้นว่า Object is not an ADODB.RecordSet or an ADODB.Record.
Parameter name: adodb
|
 |
 |
 |
 |
Date :
2015-09-21 17:13:46 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทดลองตาม คห 14 ของคุณ .tor เลยครับ ได้รับการรรับรองแล้วว่าใช้ได้ผล
|
 |
 |
 |
 |
Date :
2015-09-21 17:23:42 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบคุณ TOR_CHEMISTRY His_product ในdatabaseเป็นtext ส่วนในvbเป็นcombobox โดยที่addคือ ตัวเลขกับตัวอักษร
มันก็ยังขึ้นเหมือนเดิมอ่า
Code (VB.NET)
Public Function GetTableForm(connectionString As String, _SQL As String) As System.Data.DataTable
Dim ds As New System.Data.DataSet()
Dim conn1 As New System.Data.OleDb.OleDbConnection(connectionString)
conn1.Open()
Dim adapter1 As New System.Data.OleDb.OleDbDataAdapter(_SQL, conn1)
adapter1.Fill(ds)
Return ds.Tables(0)
End Function
Private Sub edit_Click(sender As Object, e As EventArgs) Handles edit.Click
'check for the selected item in list
If MessageBox.Show("คุณต้องการแก้ไขข้อมูลบรรทัดนั้ใช่หรือไม่ ?", "ยืนยันการแก้ไขข้อมูล", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
If Me.DataGridView1.Rows.Count > 0 Then
If Me.DataGridView1.SelectedRows.Count > 0 Then
Dim str1 As String = Me.DataGridView1.SelectedRows(0).Cells("His_product").Value
'open connnection
If Not con.State = ConnectionState.Open Then
con.Open()
End If
'get data into datatable
Dim da As OleDbDataAdapter = New OleDbDataAdapter()
Dim dt As System.Data.DataTable = GetTableForm("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\admim\Documents\ฐานข้อมูล5.accdb", "SELECT * FROM Tb_History WHERE (His_product)")
Me.semat.Text = str1
Me.txtnum.Text = dt.Rows(0).Item("His_number")
Me.txtna1.Text = dt.Rows(0).Item("His_student")
Me.txtna2.Text = dt.Rows(0).Item("His_teacher")
Me.txtdate.Text = dt.Rows(0).Item("His_date")
Me.txttime.Text = dt.Rows(0).Item("His_time")
'hide the Hisproduct to be edited in TAG of semat.text in case His_product changed
Me.semat.Tag = str1
'change button add to อัพเดทข้อมูล
Me.add.Text = "อัพเดทข้อมูล"
Me.RefreshData()
'disable button edit
Me.edit.Enabled = False
'close connection
con.Close()
End If
End If
End If
End Sub
|
 |
 |
 |
 |
Date :
2015-09-21 20:56:17 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
"SELECT * FROM Tb_History WHERE His_product like '101 ส้ม’"
WHERE ควรจะมี like หรือ = ร่วมด้วยนะครับ
|
 |
 |
 |
 |
Date :
2015-09-22 08:27:17 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
'check for the selected item in list
If MessageBox.Show("คุณต้องการแก้ไขข้อมูลบรรทัดนั้ใช่หรือไม่ ?", "ยืนยันการแก้ไขข้อมูล", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
If Me.DataGridView1.Rows.Count > 0 Then
If Me.DataGridView1.SelectedRows.Count > 0 Then
Dim intsi As string = Me.DataGridView1.SelectedRows(0).Cells("His_product").Value
'open connnection
If Not con.State = ConnectionState.Open Then
con.Open()
End If
'get data into datatable
Dim da As New OleDbDataAdapter("SELECT * FROM Tb_History " & _
" WHERE His_product = '" & intsi & "' ", con)
Dim dt As New DataTable()
da.Fill(dt)
Me.semat.Text = intsi
Me.txtnum.Text = dt.Rows(0).Item("His_number")
Me.txtna1.Text = dt.Rows(0).Item("His_student")
Me.txtna2.Text = dt.Rows(0).Item("His_teacher")
Me.txtdate.Text = dt.Rows(0).Item("His_date")
Me.txttime.Text = dt.Rows(0).Item("His_time")
'hide the Hisproduct to be edited in TAG of semat.text in case His_product changed
Me.semat.Tag = intsi
'change button add to อัพเดทข้อมูล
Me.add.Text = "อัพเดทข้อมูล"
Me.RefreshData()
'disable button edit
Me.edit.Enabled = False
End If
End If
End If
End Sub
จากโค้ดของน้อง ของบนสุดเลยนะครับ ให้ลองทำตามที่พี่แนะนำดู หลังบรรทัดข้างล่าง ให้ใส่ ตามด้านล่างนี้ดูครับ ถ้าทำแล้วโอเคจะมาเฉลยให้ครับ ว่าเพราะอะไร
Code (VB.NET)
Dim intsi As string = Me.DataGridView1.SelectedRows(0).Cells("His_product").Value
intsi = intsi.Replace("'", "")
|
 |
 |
 |
 |
Date :
2015-09-22 11:16:50 |
By :
Freedom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบคุณ Freedom มันก็ยังerrorเหมือนเดิม
|
 |
 |
 |
 |
Date :
2015-09-22 14:51:05 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูโค้ดล่าสุดที่แก้ไขหน่อยคับ
|
 |
 |
 |
 |
Date :
2015-09-22 15:01:12 |
By :
Freedom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่รู้เล่นแร่แปรธาตุอะไรหรือเปล่าครับ
จากของเดิมเริ่มต้น บันทัด 11
"SELECT * FROM Tb_History WHERE His_product = '" & intsi & "' "
มา คห 2
INSERT INTO Tb_History(His_product, His_number, His_student, His_teacher, His_date, His_time)" & _
" VALUES ('" & Me.semat.Text & "'," & Me.txtnum.Text & ",'" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & Me.txtdate.Text & "','" & _
Me.txttime.Text & "')"
และ คห 17 บันทัด 23
"SELECT * FROM Tb_History WHERE (His_product)")
งงครับ แล้วจะช่วยแก้กันยังไงไหวครับ
|
 |
 |
 |
 |
Date :
2015-09-22 15:31:20 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
If MessageBox.Show("คุณต้องการแก้ไขข้อมูลบรรทัดนั้ใช่หรือไม่ ?", "ยืนยันการแก้ไขข้อมูล", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
If Me.DataGridView1.Rows.Count > 0 Then
If Me.DataGridView1.SelectedRows.Count > 0 Then
Dim intsi As String = Me.DataGridView1.SelectedRows(0).Cells("His_product").Value
intsi = intsi.Replace("'", "")
'open connnection
If Not con.State = ConnectionState.Open Then
con.Open()
End If
'get data into datatable
Dim da As New OleDbDataAdapter("SELECT * FROM Tb_History " & _
" WHERE His_product = '" & intsi & "' ", con)
Dim dt As New DataTable()
da.Fill(dt)
Me.semat.Text = intsi
Me.txtnum.Text = dt.Rows(0).Item("His_number")
Me.txtna1.Text = dt.Rows(0).Item("His_student")
Me.txtna2.Text = dt.Rows(0).Item("His_teacher")
Me.txtdate.Text = dt.Rows(0).Item("His_date")
Me.txttime.Text = dt.Rows(0).Item("His_time")
'hide the Hisproduct to be edited in TAG of semat.text in case His_product changed
Me.semat.Tag = intsi
'change button add to อัพเดทข้อมูล
Me.add.Text = "อัพเดทข้อมูล"
Me.RefreshData()
'disable button edit
Me.edit.Enabled = False
'close connection
con.Close()
End If
End If
End If
ปล.พอเอาบรรทัดนี้ Me.semat.Tag = intsi ออก กลายเป็นaddเพิ่มเป็นบรรทัดใหม่
|
 |
 |
 |
 |
Date :
2015-09-22 15:32:24 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สร้าง richtextbox มาอัน นึ่งแล้ว เอา statement เข้าไปใส่ในนั้น
จะได้เห็น การเปลี่ยนแปลง ของ statement ก่อนการคิวรี่
จาก คห1 admin เขาอยากเห็น statement จะได้เช็คว่า ตัวแปรต่างๆ มาถูกต้องไหม
เพราะมันเกิด error จากกระบวนการคิวรี่
|
 |
 |
 |
 |
Date :
2015-09-22 15:37:45 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Dim intsi
Alert ตัวนี้ ออกมาได้ไหมครับ อยากรู้ว่ามันส่งค่าไรมา
|
 |
 |
 |
 |
Date :
2015-09-22 15:46:11 |
By :
Freedom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบคุณ TOR_CHEMISTRY
errorว่า"Syntax error (missing operator) in query expression '101 ส้ม’.
และIf MessageBox.Show("คุณต้องการแก้ไขข้อมูลบรรทัดนั้ใช่หรือไม่ ?", "ยืนยันการแก้ไขข้อมูล", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
อยากให้รู้ว่าเลือกบรรทัดนี้น่ะ
ตอบคุณ Freedom
พอเอา Dim intsi As String = Me.DataGridView1.SelectedRows(0).Cells("His_product").Value มันขึ้นว่า Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
|
 |
 |
 |
 |
Date :
2015-09-22 16:14:55 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คห 25 อยากเห็น statement
จขกท ไม่คิดที่จะเอา statement มาให้ดูมั้งเนี่ย
ก็คงเดากันไปเรื่อยๆ
ขอ statement ยังไม่ยอมเอามาให้ดู แล้วจะช่วยยังไง เอ้อเหนื่อยแทน
|
 |
 |
 |
 |
Date :
2015-09-22 16:33:26 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ของปุ่มบันทึก
Code (VB.NET)
Try
Dim cmd As New OleDbCommand
If Not con.State = ConnectionState.Open Then
'open connection
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_History(His_product, His_number, His_student, His_teacher, His_date, His_time)" & _
" VALUES ('" & Me.semat.Text & "'," & Me.txtnum.Text & ",'" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & Me.txtdate.Text & "','" & _
Me.txttime.Text & "')"
cmd.ExecuteNonQuery()
Else
'update data in table
cmd.CommandText = "Update Tb_History SET " & _
" His_product= '" & Me.semat.Text & "' " & _
" ,His_number=" & Me.txtnum.Text & _
" ,His_student= '" & Me.txtna1.Text & "' " & _
" ,His_teacher= '" & Me.txtna2.Text & "' " & _
" ,His_date= '" & Me.txtdate.Text & "' " & _
" ,His_time= '" & Me.txttime.Text & "' " & _
" WHERE His_product= " & Me.semat.Tag
cmd.ExecuteNonQuery()
End If
'refresh data in list
RefreshData()
'close connection
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
End Try
|
ประวัติการแก้ไข 2015-09-22 16:53:18
 |
 |
 |
 |
Date :
2015-09-22 16:52:23 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบคุณTOR_CHEMISTRY
ก็ยังerrorเหมือนเดิม
|
 |
 |
 |
 |
Date :
2015-09-22 17:00:21 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
การเลือกก็คือ
1.เลือกแถวที่จะแก้ไข
2.กดปุ่มแก้ไข
3.แล้วข้อมูลในแถวจะขึ้นที่textboxเพื่อให้แก้ไข
4.พอแก้เสร็จแล้วกดปุ่มอัพเดท
5.มันขึ้น error ว่า"Syntax error (missing operator) in query expression '101 ส้ม’.
ปล.มันไม่่ได้ขึ้น 101ส้ม เสมอไป มันเปลี่ยนไปตามHis_product ว่าเป็นอะไร
แถบเขียวๆคืออะไร

|
 |
 |
 |
 |
Date :
2015-09-22 17:43:01 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เหมือนเดิมเลย
|
 |
 |
 |
 |
Date :
2015-09-22 18:12:07 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอดูError เตมๆ กะโด้ด ตอนใช้
Code (VB.NET)
Dim da As New OleDbDataAdapter("SELECT * FROM Tb_History WHERE His_product like '%ส้ม%'", con)
หน่อยครับ
|
 |
 |
 |
 |
Date :
2015-09-22 18:35:15 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
If MessageBox.Show("คุณต้องการแก้ไขข้อมูลบรรทัดนั้ใช่หรือไม่ ?", "ยืนยันการแก้ไขข้อมูล", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
If Me.DataGridView1.Rows.Count > 0 Then
If Me.DataGridView1.SelectedRows.Count > 0 Then
Dim intsi As String = Me.DataGridView1.SelectedRows(0).Cells("His_product").Value
'open connnection
If Not con.State = ConnectionState.Open Then
con.Open()
End If
'get data into datatable
Dim da As New OleDbDataAdapter("SELECT * FROM Tb_History WHERE His_product like '%101ส้ม%'", con)
Dim dt As New DataTable()
da.Fill(dt)
Me.semat.Text = intsi
Me.txtnum.Text = dt.Rows(0).Item("His_number")
Me.txtna1.Text = dt.Rows(0).Item("His_student")
Me.txtna2.Text = dt.Rows(0).Item("His_teacher")
Me.txtdate.Text = dt.Rows(0).Item("His_date")
Me.txttime.Text = dt.Rows(0).Item("His_time")
'hide the Hisproduct to be edited in TAG of semat.text in case His_product changed
Me.semat.Tag = intsi
'change button add to อัพเดทข้อมูล
Me.add.Text = "อัพเดทข้อมูล"
Me.RefreshData()
'disable button edit
Me.edit.Enabled = False
'close connection
con.Close()
End If
End If
End If
error ที่da.Fill(dt)ขึ้นว่า "Syntax error (missing operator) in query expression '101 ส้ม’.
|
ประวัติการแก้ไข 2015-09-22 18:59:28
 |
 |
 |
 |
Date :
2015-09-22 18:57:38 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Dim da As New OleDbDataAdapter("SELECT * FROM Tb_History WHERE His_product like '%ส้ม%'", con)
|
 |
 |
 |
 |
Date :
2015-09-23 07:46:56 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แต่มันไม่ได้เป็นส้มเสมอไปเพราะ ถ้าแถวที่จะแก้ไขเป็น มะละกอ มังคุด ก็จะขึ้นตามproductที่จะแก้ไข
|
 |
 |
 |
 |
Date :
2015-09-23 14:09:46 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขึ้นขณะรันโปรแกรม โดยจะที่การกดอัพเดทข้อมูล
ขึ้นerrorว่า "Syntax error (missing operator) in query expression 'His_product= 101ส้ม’.
|
 |
 |
 |
 |
Date :
2015-09-23 18:25:48 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Dim da As New OleDbDataAdapter("SELECT * FROM Tb_History WHERE His_product like '%ส้ม%'", con)
แค่ อยากรู้ว่ามันเป็นที่ ตัวไหนถ้า
Code (VB.NET)
Dim da As New OleDbDataAdapter("SELECT * FROM Tb_History WHERE His_product like '%ส้ม%'", con)
ยัง Error นั่นก็หมายความว่าเป็นที่ database หรือ DataAdapter ต่างๆ
แต่ถ้าไม่ Error แสดงว่าเป็นที่ SQL ซึ่งไม่น่าจะเป็นไปได้
แล้วก็เอาหน้า ฟอร์มตอนใช้งาน มาให้พี่ๆเขาดูด้วยครับจะได้แก้ปัญหาตรงจุด
เหนื่อยจะงม 55555
|
ประวัติการแก้ไข 2015-09-23 18:38:10
 |
 |
 |
 |
Date :
2015-09-23 18:32:18 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เหมือนมันจะเกี่ยวข้องกับปุ่มบันทึก
เพราะตอนนี้บันทึกไม่ได้แล้ว โดยมันerrorขณะรันโปรแกรมโดยขึ้นว่า "Syntax error (missing operator) in query expression 'His_product= 102 เกลี่ยวC-Clamp’.
อันนี้เป็นโค้ดปุ่มบันทึก
Code (VB.NET)
Try
Dim cmd As New OleDbCommand
If Not con.State = ConnectionState.Open Then
'open connection
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_History(His_product, His_number, His_student, His_teacher, His_date, His_time)" & _
" VALUES ('" & Me.semat.Text & "'," & Me.txtnum.Text & ",'" & _
Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & Me.txtdate.Text & "','" & _
Me.txttime.Text & "')"
cmd.ExecuteNonQuery()
Else
'update data in table
cmd.CommandText = "Update Tb_History SET " & _
" His_product= '" & Me.semat.Text & "' " & _
" ,His_number=" & Me.txtnum.Text & _
" ,His_student= '" & Me.txtna1.Text & "' " & _
" ,His_teacher= '" & Me.txtna2.Text & "' " & _
" ,His_date= '" & Me.txtdate.Text & "' " & _
" ,His_time= '" & Me.txttime.Text & "' " & _
" WHERE His_product= " & Me.semat.Tag
cmd.ExecuteNonQuery()
End If
'refresh data in list
RefreshData()
'close connection
con.Close()
MessageBox.Show("บันทึกลงตารางเรียบร้อยแล้ว")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
End Try
และพอกดปุ่มแก้ไข มันerrorที่ Code (VB.NET)
Dim intsi As String = Me.DataGridView1.SelectedRows(0).Cells("His_product").Value
โดยขึ้นว่า Column named His_product cannot be found.
Parameter name: columnName
โค้ดปุ่มแก้ไข
Code (VB.NET)
If MessageBox.Show("คุณต้องการแก้ไขข้อมูลบรรทัดนั้ใช่หรือไม่ ?", "ยืนยันการแก้ไขข้อมูล", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
If Me.DataGridView1.Rows.Count > 0 Then
If Me.DataGridView1.SelectedRows.Count > 0 Then
Dim intsi As String = Me.DataGridView1.SelectedRows(0).Cells("His_product").Value
'open connnection
If Not con.State = ConnectionState.Open Then
con.Open()
End If
'get data into datatable
Dim da As New OleDbDataAdapter("SELECT * FROM Tb_History " & _
" WHERE His_product = '" & intsi & "' ", con)
Dim dt As New DataTable()
da.Fill(dt)
Me.semat.Text = intsi
Me.txtnum.Text = dt.Rows(0).Item("His_number")
Me.txtna1.Text = dt.Rows(0).Item("His_student")
Me.txtna2.Text = dt.Rows(0).Item("His_teacher")
Me.txtdate.Text = dt.Rows(0).Item("His_date")
Me.txttime.Text = dt.Rows(0).Item("His_time")
'hide the Hisproduct to be edited in TAG of semat.text in case His_product changed
Me.semat.Tag = intsi
'change button add to อัพเดทข้อมูล
Me.add.Text = "อัพเดทข้อมูล"
Me.RefreshData()
'disable button edit
Me.edit.Enabled = False
End If
End If
End If
อันนี้เป็นรูปที่คุณต้องการ

|
 |
 |
 |
 |
Date :
2015-09-23 21:38:56 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้สามารถทำได้แล้วบ้างส่วนคือ แก้ในส่วนของปุ่มบันทึก
เป็น " WHERE His_product= '" & Me.semat.Text & "' "
แต่ทำไมพอแก้จำนวนในแถวของสินค้านั้น
มันถึงไปแก้จำนวนที่มีชื่อเหมือนกันด้วยล่ะ
|
ประวัติการแก้ไข 2015-09-23 22:12:11 2015-09-23 22:19:45 2015-09-23 22:25:52
 |
 |
 |
 |
Date :
2015-09-23 22:07:37 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมรู้แระปัญหาคือไร
ว่างๆๆๆๆๆค่อยมาตอบมันง่ายเกิน
ถ้าเอามาดูแบบนี้ตั้งแต่แรกก็คงไม่เป็นมหากาพย์กากๆแบบนี้
ที่สำคัญมันส่อให้เห็นว่าคุณไม่ใส่ใจงานคุณเลย
ทั้งๆที่หลาย ๆ คนอยากช่วยแก้ปัญหาให้คุณ
งมเองละกันมันง่ายเกิน   
|
 |
 |
 |
 |
Date :
2015-09-24 08:14:18 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณสำหรับคำแนะนำ ซึ่งก็ต้องขอโทษหลายๆคนที่เข้ามาช่วย แต่เราอาจจะไม่ได้ให้คำตอบที่เป็นประโยชน์นัก
แต่อยากถามว่าทำไมพอแก้จำนวนแถวที่เลือกแล้ว
มันไปแก้จำนวนที่มีชื่ิอเหมือนกันด้วยทั้งหมดเลย
|
 |
 |
 |
 |
Date :
2015-09-25 17:37:35 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เวลาอัพเดท พยายามใช้ primary key ใน where clause
|
 |
 |
 |
 |
Date :
2015-09-25 19:06:28 |
By :
NewbiePHP |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีอยู่คอลัมIDอยู่โดยได้ตั้งเป็นAutonumberในฐานข้อมูล
ซึ่งในvbไม่ได้มีการอ้างอิงเลย
ดังนั้นควรเขียนWHRERยังไง
|
 |
 |
 |
 |
Date :
2015-09-25 19:16:32 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|



|
 |
 |
 |
 |
Date :
2015-09-25 19:36:32 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ติดปัญหาคือมันไปแก้แถวอื่นที่มีชื่ิอเหมือนกันด้วยทั้งหมดเลย
Code (VB.NET)
Dim inti As Integer
'update data in table
cmd.CommandText = " Update Tb_History SET " & _
" His_product= '" & Me.semat.Text & "' " & _
" ,His_number=" & Me.txtnum.Text & _
" ,His_student= '" & Me.txtna1.Text & "' " & _
" ,His_teacher= '" & Me.txtna2.Text & "' " & _
" ,His_date= '" & Me.txtdate.Text & "' " & _
" ,His_time= '" & Me.txttime.Text & "' " & _
" WHERE ID=" & inti & ""
ใช่แบบนี้หรือป่าว ซึ่งมันกดอัพเดทได้ แต่ไม่มีอะไรเปลี่ยนแปลงตามที่แก้ไข
|
ประวัติการแก้ไข 2015-09-27 02:55:13 2015-09-27 02:58:57
 |
 |
 |
 |
Date :
2015-09-25 21:12:41 |
By :
peemes101 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่าเค้าดีบัคโค้ดไม่เป็นหรือเปล่า ?
กดหน้าเลขบรรทัดให้เป็นจุดแดงครับ มันจะทำงานแล้วมาหยุดตรงนั้น เราจะดูความเปลี่ยนแปลงของค่าต่างๆที่เราประกาศได้
เช่น
strSQL ก่อนที่เอาไปส่งให้ oledbadapter ก็ดักแอบดูค่านี้ก่อนว่าเราได้ sql statment แบบไหน
เสร็จแล้วก็อปปี้ไว้ ลองเอาไปรันใน sql server management studio ดูว่าเราได้เชื่อมคำสั่ง statement ถูกต้องหรือเปล่า
ค่อยๆทำไปนะ วันนี้คงเอาไปนอนฝันแล้วมั้งป่านนี้ 555+
เห็นถามกันมาตั้งนานแระ
|
 |
 |
 |
 |
Date :
2015-09-26 00:05:20 |
By :
deksoke |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|