 |
|
เกิด Syntax error in INSERT INTO statement. VB2010 |
|
 |
|
|
 |
 |
|
เกิด Syntax error in INSERT INTO statement สำหรับโค้ดชุดนี้ค่ะ
Code (VB.NET)
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Try
Dim sqlquery As String = "INSERT INTO MainGory(MainID, AmenityHead, AmenityDetail, PointN, ,StandardN, AmenityID, CategoryID) VALUES ('" & txtMainID.Text & "', '" & txtAmenDe.Text & "','" & txtDetail.Text & "','" & txtNum.Text & "','" & txtDIV.Text & "', '" & txtAM1.Text & "','" & txtCG1.Text & "')"
Dim sqlcommand As New OleDbCommand
With sqlcommand
.CommandText = sqlquery
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("บันทึกข้อมูลเรียบร้อยแล้วค่ะ", vbOKOnly, "Save Data")
txtAmenDe.Text = ""
txtDetail.Text = ""
txtNum.Text = ""
txtDIV.Text = ""
txtAM1.Text = ""
txtCG1.Text = ""
Dim cn As New System.Data.OleDb.OleDbConnection(connstring)
Dim da As New System.Data.OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim sql1 As String = "select * from MainGory"
da.SelectCommand = New System.Data.OleDb.OleDbCommand(sql1, cn)
da.Fill(ds, "MainGory")
DataGridView1.DataSource = ds.Tables("MainGory")
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
Tag : .NET, VS 2010 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2013-05-10 21:11:19 |
By :
borobirt |
View :
1065 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Dim sqlquery As String = "INSERT INTO MainGory(MainID, AmenityHead, AmenityDetail, PointN, ,StandardN, AmenityID, CategoryID) VALUES ('" & txtMainID.Text & "', '" & txtAmenDe.Text & "','" & txtDetail.Text & "','" & txtNum.Text & "','" & txtDIV.Text & "', '" & txtAM1.Text & "','" & txtCG1.Text & "')"
ผมว่าควรจะ Property .Parameters แทนดีกว่านะ
|
 |
 |
 |
 |
Date :
2013-05-10 22:15:16 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 1 เขียนโดย : ikikkok เมื่อวันที่ 2013-05-10 22:15:16
รายละเอียดของการตอบ ::
Code (VB.NET)
Dim cmd As New OleDbCommand
cmd.Connection = conn
cmd.CommandText = "INSERT INTO Credit(Credit_ID, Member_ID, Crebit, Total, Date, Remark) VALUES ('" & txtCreID.Text & "','" & txtMemberID.Text & "','" & txtCredit.Text & "','" & txtTotal.Text & "','" & DateTimePicker1.Text & "','" & txtRemark.Text & "')"
With cmd
cmd.ExecuteNonQuery()
conn.Close()
End With
MsgBox("บันทึกข้อมูลเรียบร้อยแล้วค่ะ", vbOKOnly, "Save Data")
อันนี้ก็ติดเหมือนกันค่ะ
|
 |
 |
 |
 |
Date :
2013-05-24 18:18:56 |
By :
borobirt |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขึ้น error ว่าอย่างไรครับ
|
 |
 |
 |
 |
Date :
2013-05-25 18:03:55 |
By :
01000010 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Dim sqlquery As String = "INSERT INTO MainGory(MainID, AmenityHead, AmenityDetail, PointN, ,StandardN, AmenityID, CategoryID) VALUES ('" & txtMainID.Text & "', '" & txtAmenDe.Text & "','" & txtDetail.Text & "','" & txtNum.Text & "','" & txtDIV.Text & "', '" & txtAM1.Text & "','" & txtCG1.Text & "')"
การเชื่อมต่อสตริง โดยใช้ เครื่องหมาย นมหนู, ฟันหนู, สองหู (Double Quote), หูเดียว (Single Quote)
ถ้าเลี่ยงได้ก็อย่าลังเลครับ โดยใช้ Class StringBuilder() หรือ HTML Tag
Code (VB.NET)
Dim sqlString As New StringBuilder()
sqlString.Append("Select * From ")
หรือใช้ HTML Tab
Code (VB.NET)
Dim sqlString As String = <ผัวจ๋า>
-------------------------------------- Select * from TableXXX
-------------------------------------- Where
-------------------------------------- ProductID = 1234
-----------------------------------</ผัวจ๋า>
เวลาจะใช้งานก็ sqlString.ToString()
|
 |
 |
 |
 |
Date :
2013-05-26 07:28:26 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|