VB.NET อยากรู้ครับทำไมบันทึกข้อมูลลงฐานไม่ได้ครับ (Syntax error in INSERT INTO statement.)
อยากรู้ครับทำไมบันทึกข้อมูลลงฐานไม่ได้ครับ พอกดปุ่มบันทุกข้อมูล
มันฟ้องว่า >>>>> Record can not insert Error (Syntax error in INSERT INTO statement.) <<<<<<แบบนี้ครับ
โค้ดน่ะครับ........<<<<
Code (VB.NET)
Imports System.IO
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data
Partial Class Customers
Inherits System.Web.UI.Page
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim objConn As New OleDbConnection
Dim Connection As OleDbConnection
'Dim objConn As OleDbConnection'
'Dim objCmd As OleDbCommand'
Dim objCmd As New OleDbCommand
Dim strConnString, strSQL As String
'strConnString = "Server=localhost;UID=sa;PASSWORD=;database=POSDB;Max Pool Size=400;Connect Timeout=600;"'
objCmd = New OleDbCommand(strSQL, objConn)
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database/POSDB.mdb") & ";Jet OLEDB:Database Password=;"
objConn.ConnectionString = strConnString
objConn.Open()
strSQL = "INSERT INTO tblcustomer ([CustomerCode], [CustomerName], [Address], [Memo], [Nick], [Age], [IDCard], [Birthday], [AdHome], [AdOffice] [Other], [How], [Dumnern], [Aregon], [Ownta], [Tawparsri], [Prb], [Tumneam], [YodBun], [Otherss], [Rum], [Rubsud], [ngensod], [Rubngen], [TudBun], [Phuchao], [jaonatee], [tho], [PidBun], [INV], [Fax], [Lam], [OwnBun], [BunChee], [NumBun], [Kammasit], [saka], [Car], [Run], [jodta], [MM], [CarID], [Parsri], [NumSecurity], [Numtung], [CarCare], [NumMike], [Buy], [MKT], [Yodjud], [Pon], [Ngud], [Ngudsud], [ponrom], [NgudRak], [BK], [Money]) " & _
" VALUES " & _
" ('" & Me.txtCustomerCode.Text & "','" & Me.txtCustomerName.Text & "','" & Me.txtAddress.Text & "','" & Me.txtMemo.Text & "','" & Me.txtNick.Text & "','" & Me.txtAge.Text & "','" & Me.txtIdcard.Text & "','" & Me.txtBirthday.Text & "','" & Me.txtAdHome.Text & "','" & Me.txtAdOffice.Text & "','" & Me.txtOther.Text & "','" & Me.txtHow.Text & "','" & Me.txtDumnern.Text & "','" & Me.txtAregon.Text & "','" & Me.txtOwnta.Text & "','" & Me.txtTawparsri.Text & "','" & Me.txtPrb.Text & "','" & Me.txtTumneam.Text & "','" & Me.txtYodBun.Text & "','" & Me.txtOtherss.Text & "','" & Me.txtRum.Text & "','" & Me.txtRubsud.Text & "','" & Me.txtngensod.Text & "','" & Me.txtRubngen.Text & "','" & Me.txtTudBun.Text & "','" & Me.txtPhuchao.Text & "','" & Me.txtjaonatee.Text & "','" & Me.txttho.Text & "','" & Me.txtPidBun.Text & "','" & Me.txtINV.Text & "','" & Me.txtFax.Text & "','" & Me.txtLam.Text & "','" & Me.txtOwnBun.Text & "','" & Me.txtBunChee.Text & "','" & Me.txtNumBun.Text & "','" & Me.txtKammasit.Text & "','" & Me.txtsaka.Text & "','" & Me.txtCar.Text & "','" & Me.txtRun.Text & "','" & Me.txtjodta.Text & "','" & Me.txtMM.Text & "','" & Me.txtCarID.Text & "','" & Me.txtParsri.Text & "','" & Me.txtNumSecurity.Text & "','" & Me.txtNumtung.Text & "','" & Me.txtCarCare.Text & "','" & Me.txtNumMike.Text & "','" & Me.txtBuy.Text & "','" & Me.txtMKT.Text & "','" & Me.txtYodjud.Text & "','" & Me.txtPon.Text & "','" & Me.txtNgud.Text & "','" & Me.txtNgudsud.Text & "','" & Me.txtponrom.Text & "', '" & Me.txtNgudRak.Text & "','" & Me.txtBK.Text & "','" & Me.txtMoney.Text & "')"
objCmd = New OleDbCommand
'objConn.ConnectionString = strConnString'
'objConn.Open()'
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Try
objCmd.ExecuteNonQuery()
Me.lblStatus.Text = "Record Inserted"
Me.lblStatus.Visible = True
Catch ex As Exception
Me.lblStatus.Visible = True
Me.lblStatus.Text = "Record can not insert Error (" & ex.Message & ")"
End Try
objConn.Close()
objConn = Nothing
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
Tag : ASP, Ms Access, Web (ASP.NET)
Date :
2013-03-14 15:27:20
By :
Prajoubdls
View :
1509
Reply :
4
เป็นที่ SQL Statement นี่แหละครับ แต่ไม่รู้ว่าตรงไหน เพระา Code เยอะจัดครับ
Date :
2013-03-14 15:32:24
By :
mr.win
อ๋อ ครับ
อย่างนี้ผมต้องทำไงครับถึงจะรู้ว่ามันผิดตรงไหน พอมีแนวทางแก้ไหมครับ
ผมเขียนมาหลายสัปดาห์แล้วยังไม่เสร็จซักที ยัง"งงงง"กับตรงนี้ละครับ
Date :
2013-03-14 15:45:51
By :
Prajoubdls
ลอง Debug เอาค่า SQL ออกมาดูหน่อยครับ
Date :
2013-03-14 15:50:59
By :
mr.win
เป็นที่ตรงนี้อ่ะจะแก้ไงเหรอครับ
Date :
2013-03-14 16:27:21
By :
Prajoubdls
Load balance : Server 00