Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > พอดีไม่ค่อยมีความรู้ค่ะ error ฟ้องว่าSyntax error in INSERT INTO statement.ช่วยแก้ให้หน่อยนะค่ะ ขอบคุณล่วงหน้าค่ะ



 

พอดีไม่ค่อยมีความรู้ค่ะ error ฟ้องว่าSyntax error in INSERT INTO statement.ช่วยแก้ให้หน่อยนะค่ะ ขอบคุณล่วงหน้าค่ะ

 



Topic : 058329

Guest




Code (VB.NET)
  Private Sub btnsadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsadd.Click
        If txtid.Text = "" Then
            MessageBox.Show("กรุณากรอกรหัสโครงการที่ต้องการเพิ่มด้วยค่ะ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtid.Focus()
            txtid.SelectAll()
            Exit Sub
        End If

        If txtname1.Text = "" Then
            MessageBox.Show("กรุณากรอกชื่อโครงการที่ต้องการเพิ่มด้วยค่ะ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtname1.Focus()
            txtname1.SelectAll()
            Exit Sub
        End If

        If cba.SelectedIndex = 0 Then
            MessageBox.Show("กรุณาเลือกหน่วยงานที่เสนอโครงการด้วยค่ะ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

        If txtm1a.Text = "" Then
            MessageBox.Show("กรุณากรอกงบประมาณที่เสนอด้วยค่ะ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtm1a.Focus()
            txtm1a.SelectAll()
            Exit Sub
        End If

        If txtm2a.Text = "" Then
            MessageBox.Show("กรุณากรอกงบประมาณที่อนุมัติด้วยค่ะ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtm2a.Focus()
            txtm2a.SelectAll()
            Exit Sub
        End If

        If txtm3a.Text = "" Then
            MessageBox.Show("กรุณากรอกงบประมาณที่ได้รับการจัดสรรด้วยค่ะ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtm3a.Focus()
            txtm3a.SelectAll()
            Exit Sub
        End If

        If rd1a.Checked = False And rd2a.Checked = False Then
            MessageBox.Show("กรุณาเลือกแหล่งงบประมาณด้วยค่ะ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
        If rd1a.Checked = True And txtwritea.Text <> "" Then
            MessageBox.Show("กรอกข้อมูลแหล่งที่มาของงบประมาณผิดพลาดกรุณาตรวจสอบ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If


        If rd2a.Checked = True And txtwritea.Text = "" Then
            MessageBox.Show("กรุณาระบุแหล่งงบประมาณด้วยค่ะ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

        If txtyear1.Text = "" Then
            MessageBox.Show("กรุณากรอกปีงบประมาณด้วยค่ะ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtyear1.Focus()
            txtyear1.SelectAll()
            Exit Sub
        End If

        If Ra1a.Checked = False And Ra2a.Checked = False And Ra3a.Checked = False And Ra4a.Checked = False Then
            MessageBox.Show("กรุณาเลือกสถานะของโครงการด้วยค่ะ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

        Dim sqlAdd As String
        Dim comAdd As New OleDbCommand
        If MessageBox.Show("คุณต้องการเพิ่มโครงการใหม่ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

            sqlAdd = "INSERT INTO Project1(IDPro1,NamePro1)"
            sqlAdd &= "INSERT INTO Agencies(NameAgen)"
            sqlAdd &= "INSERT INTO Total Budget1(Budget request,Budget approval,Statement received)"
            sqlAdd &= "INSERT INTO Project Detail1(Year)"

            sqlAdd &= "VALUES('" & txtid.Text & "',"
            sqlAdd &= "'" & txtname1.Text & "',"
            sqlAdd &= "'" & cba.ValueMember & "',"
            sqlAdd &= "'" & txtyear1.Text & "',"
            sqlAdd &= "'" & txtm1a.Text & "',"
            sqlAdd &= "'" & txtm2a.Text & "',"
            sqlAdd &= "'" & txtm3a.Text & "')"

            With Conn
                If .State = ConnectionState.Open Then .Close()
                .ConnectionString = strConn
                .Open()
            End With

            With comAdd
                .CommandType = CommandType.Text
                .CommandText = sqlAdd
                .Connection = Conn
                .ExecuteNonQuery()
            End With

            MessageBox.Show("คุณได้เพิ่มโครงการใหม่เรียบร้อยแล้ว", "ผลการดำเนินการ", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub




Tag : .NET, Ms Access, VB.NET







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-04-05 15:33:56 By : อ่อนหัด View : 1116 Reply : 2
 

 

No. 1

Guest


Syntax การเขียน Code Insert ผิดนะครับ

Syntax ที่ถูกต้องคือ

Code
INSERT INTO table_name
VALUES (value1, value2, value3,...)


หรือ

Code
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)



ลองดูนะครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-05 16:30:59 By : Guest
 


 

No. 2

Guest


Code (VB.NET)
Private Sub btnSave_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim sqlAdd As String
        Dim sqlEdit As String
        Dim comAdd As New OleDbCommand
        Select Case btnChk 'ตรวจสอบการคลิกปุ่ม
            Case "Add" 'กรณีถ้าคลิกปุ่ม เพิ่ม
                'ตรวจสอบการป้อนข้อมูลว่าครบถ้วนหรือไม่
                If (txtName.Text = "") Or (txtPosition.Text = "") Or (txtSex.Text = "") Or (txtSalary.Text = "") Then
                    MsgBox("โปรดป้อนข้อมูลให้ครบ")
                    txtName.Focus()
                    Exit Sub
                End If
                'คำสั่ง SQL เพื่อแทรกข้อมูลในตาราง tblCustomer
                sqlAdd = "Insert Into tblCustomer(CustName,Position,Sex,Salary)"
                sqlAdd &= " VALUES ('" & txtName.Text & "',"
                sqlAdd &= "'" & txtPosition.Text & "',"
                sqlAdd &= "'" & txtSex.Text & "',"
                sqlAdd &= "'" & txtSalary.Text & "')" 'การสั่งออปเจค comAdd ให้ทำงาน
                With comAdd
                    .CommandType = CommandType.Text 'เซตประเภทคอมมาน
                    .CommandText = sqlAdd 'ใส่ชุดคำสั่ง SQL
                    .Connection = Conn 'บอกว่าจะไปทางไหน
                    .ExecuteNonQuery() 'ไปทำงานได้ (ส่งคำสั่งไปแบบไม่ต้องการผลลัพธ์คืนมา)
                End With
                MsgBox("บันทึกข้อมูลเรียบร้อย") 'แสดง MessageBox ว่าได้บันทึกข้อมูลแล้ว
                ShowAllCustomers() 'แสดงข้อมูลใน DataGridView
            Case "Update" 'กรณีถ้าคลิกปุ่ม แก้ไข
                'คำสั่ง SQL ในการปรับปรุงข้อมูลในตาราง tblCustomer ตาม รหัสพนักงาน
                sqlEdit = "UPDATE tblCustomer"
                sqlEdit &= " SET CustName = '" & txtName.Text & "',"
                sqlEdit &= " Position = '" & txtPosition.Text & "',"
                sqlEdit &= " Sex = '" & txtSex.Text & "',"

                sqlEdit &= " Salary = '" & txtSalary.Text & "'"
                sqlEdit &= " WHERE (CustID = " & CInt(txtID.Text) & ")"
                'การสั่งออปเจค comAdd ให้ทำงาน
                With comAdd
                    .CommandType = CommandType.Text
                    .CommandText = sqlEdit
                    .Connection = Conn
                    .ExecuteNonQuery()
                End With
                MsgBox("แก้ไขข้อมูลเรียบร้อย") 'แสดง MessageBox ว่าได้แก้ไขข้อมูลแล้ว
                ShowAllCustomers() 'แสดงข้อมูลใน DataGridView
            Case Else
                MsgBox("ไม่มีการทำงาน")
        End Select
        btnInsert.Enabled = True 'ปุ่ม เพิ่ม เปิดการทำงาน
        btnUpdate.Enabled = True 'ปุ่ม แก้ไข เปิดการทำงาน
        btnDelete.Enabled = True 'ปุ่ม ลบ เปิดการทำงาน
        btnSave.Enabled = False 'ปุ่ม ตกลง เปิดการทำงาน
        btnCancel.Enabled = False 'ปุ่ม ยกเลิก เปิดการทำงาน
    End Sub

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-10-02 15:24:54 By : ll
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : พอดีไม่ค่อยมีความรู้ค่ะ error ฟ้องว่าSyntax error in INSERT INTO statement.ช่วยแก้ให้หน่อยนะค่ะ ขอบคุณล่วงหน้าค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่