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 tว่า he select statement includes a reserved word or an argument name that is misspelled or missing ตรง da.Fill(dt) ช่วยดูให้หน่อย



 

ขึ้นerror tว่า he select statement includes a reserved word or an argument name that is misspelled or missing ตรง da.Fill(dt) ช่วยดูให้หน่อย

 



Topic : 117746



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์




-ผิดที่ da.Fill(dt)

-และได้สร้างID ในฐานข้อมูล เป็น autonumber เลยไม่ได้selectมา ไม่ทราบว่าถูกหรือป่าว

และนี้เป็นโค้ดทั้งหมด โดยปุ่มbutton1คือปุ่มเพิ่มข้อมูล ลงในdatagridview

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 selectitemmat as [ID_Product], " & _
                                    "txtnum as [out_num],txtna1 as [out_student],txtna2 as [out_store]," & _
                                    "DateTimePicker1 as [out_date]," &
                                    "FROM tb_Out_Product ORDER BY selectitemmat",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()

  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 if it is not yet open
            con.Open()
        End If
        cmd.Connection = con

        'check whether add new or update
        If Me.txtmat.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.selectitemmat.SelectedItem & ",'" & Me.txtnum.Text & "','" & _
                              Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & _
                             Me.DateTimePicker1.Text & "')"

            cmd.CommandType = CommandType.Text
            cmd.ExecuteNonQuery()
        Else
            'update data in table
            cmd.CommandText = "Update tb_Out_Product" & _
                            "SET ID_Product" & Me.selectitemmat.SelectedItem  & _
                            ",out_num" & Me.txtnum.Text & "'" & _
                            ",out_student" & Me.txtna1.Text & "'" & _
                            ",out_store" & Me.txtna2.Text & "'" & _
                            ",out_date1" & Me.DateTimePicker1.Text & "'" & _
                            "WHERE ID_Product=" & Me.txtmat.Tag
            cmd.ExecuteNonQuery()
        End If
        'refresh data in list
        RefreshData()

        'clear form
        Me.Button6.PerformClick()

        'close connection
        con.Close()






Tag : .NET









ประวัติการแก้ไข
2015-07-13 08:19:27
2015-07-13 08:21:10
2015-07-13 08:34:55
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-07-13 08:15:54 By : peemes101 View : 1321 Reply : 41
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
reserved word


ลองดูพวกที่เกี่ยวกับคำสงวน Reserved Word น่ะครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-13 10:09:29 By : mr.win
 


 

No. 2



โพสกระทู้ ( 374 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2015-07-13 10:09:29
รายละเอียดของการตอบ ::
ผมว่าตรงนี้แน่เลย "DateTimePicker1 as [out_date],"

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-13 12:29:33 By : Balll2iFFer
 

 

No. 3



โพสกระทู้ ( 821 )
บทความ ( 0 )



สถานะออฟไลน์


DateTimePicker1 as [out_date], === Comma เกินมาครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-13 12:46:30 By : fonfire
 


 

No. 4



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


หลังจากแก้ตามที่ทุกคนบอก

ผลคือชี้ที่จุดเดิม ที่ da.Fill(dt)

แต่เปลี่ยนคำerror คือ no value given for one or more required parameters
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-13 19:58:24 By : peemes101
 


 

No. 5



โพสกระทู้ ( 374 )
บทความ ( 0 )



สถานะออฟไลน์


ลองศึกษาพวก Parameter ก่อนครับ รู้สึกแหม่งๆอ่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-13 21:19:36 By : Balll2iFFer
 


 

No. 6



โพสกระทู้ ( 821 )
บทความ ( 0 )



สถานะออฟไลน์


ลองเอา sql command ที่ได้ไป execute ที่ sql management ครับว่าได้ไหม
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-14 07:39:41 By : fonfire
 


 

No. 7



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


พอดีเป็นมือใหม่
คือฐานข้อมูลที่ใช้เป็น table ของaccess
แล้วทำไมถึงบอกว่า ลองเอา sql command ที่ได้......

หรือว่าทำผิดตั้งแต่ต้น
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-14 08:34:30 By : peemes101
 


 

No. 8



โพสกระทู้ ( 821 )
บทความ ( 0 )



สถานะออฟไลน์


อ้าววว ขออภัยครับ ไม่ได้สังเกตุว่าเป็น access
ผมไม่ค่อยได้ใช้ access น่ะครับ ผิดถูกขออภัย


ลองเอา command ที่ได้ไป run ใน access query ดูครับว่ามันทำงานได้หรือปล่าว
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-14 08:43:56 By : fonfire
 


 

No. 9



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ได้ทำการแก้ Sql ยังเอามาอัฟใหม่หน่อยครับ
เพราะถ้า SQL
Code (VB.NET)
Dim da As New OleDbDataAdapter("SELECT selectitemmat as [ID_Product], " & _
                                    "txtnum as [out_num],txtna1 as [out_student],txtna2 as [out_store]," & _
                                    "DateTimePicker1 as [out_date]," &
                                    "FROM tb_Out_Product ORDER BY selectitemmat",con)


มันแปลกๆยุนะ

txtnum txtna1 txtna1 DateTimePicker1 มันใช่ตารางใน tb_Out_Product เหรอครับ
ทำไมชื่อมันไม่ยักเหมือน

Code (VB.NET)
cmd.CommandText = " INSERT INTO tb_Out_Product(ID_Product, out_num, out_student, out_store, out_date)" & _
                              " VALUES (" & Me.selectitemmat.SelectedItem & ",'" & Me.txtnum.Text & "','" & _
                              Me.txtna1.Text & "','" & Me.txtna2.Text & "','" & _
                             Me.DateTimePicker1.Text & "')"


ทั้งๆที่น่าจะเป็นตารางเดียวกัน

ลองใช้แบบนี้ดูครับ

Code (VB.NET)
Dim da As New OleDbDataAdapter("SELECT * FROM tb_Out_Product ORDER BY ID_Product",con)


วิธีการเช็คว่าเกิดจาก SQL ของเรารึป่าวเอาแบบบ้านๆคือให้เริ่มจาก SELECT * FROM ครับ
ถ้าแบบนี้แล้วได้ก็แสดงว่าที่ผ่านมาเป็นที่ syntex SQL ก็ค่อยๆไปศึกษาดู


http://www.w3schools.com/sql/sql_alias.asp
https://www.thaicreate.com/tutorial/sql-alias.html
https://www.thaicreate.com/tutorial/sql.html


แต่ถ้ายัง Error อยู่ก็หาสาเหตุต่อไปแบบบ้านๆตามเคยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-14 09:08:08 By : lamaka.tor
 


 

No. 10



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


คือเป็นTable จาก Access
และไม่ได้ดึงID จากtableมา เพราะตั้งเป็นautonumberไว้

ดังนั้น ถ้าเป็นtale จาก access แสดงว่าที่เขียนว่าคือ ผิด ใช่หรือป่าว

และขอดูโค้ดที่เป็นvb+access ของปุ่มเพิ่มข้อมูลลงในdatagridview ที่เป็นตัวอย่างหน่อย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-14 09:26:12 By : peemes101
 


 

No. 11



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ที่ทำน่ะถูกแล้วครับ

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 * FROM tb_Out_Product ORDER BY ID_Product",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()
Ebd Sub

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-14 09:32:27 By : lamaka.tor
 


 

No. 12



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


ขึ้นerrorที่ cmd.ExecuteNonQuery() แจ้งว่า Syntax error in UPDATE statement.






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 * FROM tb_Out_Product ORDER BY ID_Product", 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


    Dim cmd As New OleDbCommand
        If Not con.State = ConnectionState.Open Then
            'open connection if it is not yet open
            con.Open()
        End If
        cmd.Connection = con


        
            If Not con.State = ConnectionState.Open Then
                'open connection if it is not yet open
                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_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.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.Text & "'" & _
                            "WHERE ID_Product=" & Me.semat.Tag
            cmd.ExecuteNonQuery()

        End If
            'close connection
            con.Close()
Endsub



ประวัติการแก้ไข
2015-07-14 11:30:12
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-14 11:21:25 By : peemes101
 


 

No. 13



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 12 เขียนโดย : peemes101 เมื่อวันที่ 2015-07-14 11:21:25
รายละเอียดของการตอบ ::
ก่อนอื่นต้องยินดีด้วยที่ผ่านมาได้นิดนึงแระ(แต่ดูท่าทางจะอีกไกลนะนั่น 555)

แนะนำให้ศึกษาเรื่อง SQL ครับ
http://www.w3schools.com/sql/sql_alias.asp
https://www.thaicreate.com/tutorial/sql.html

ไม่งั้นปัญหาง่ายๆแบบนี้คุณจะได้เจอเกือบทุกวันครับ
อ้อ เรื่อง Syntax error in UPDATE statement

Code (SQL)
UPDATE [Table-Name] SET Column1='Value1',Column2='Value2',... WHERE clause


คิดว่าทำผิดรูปแบบตรงไหนละครับลองๆมองดู

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-14 14:47:42 By : lamaka.tor
 


 

No. 14



โพสกระทู้ ( 1,636 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

57.cmd.CommandText = "Update tb_Out_Product" & _ 58."SET ID_Product" & Me.semat.SelectedItem & _ 59.",out_num = '" & Me.txtnum.Text & "'" & _ 60.",out_student" & Me.txtna1.Text & "'" & _ 61.",out_store" & Me.txtna2.Text & "'" & _ 62.",out_date1" & Me.txtdate.Text & "'" & _ 63."WHERE ID_Product=" & Me.semat.Tag


สีแดงใส่ให้ครบทุก field ที่ต้องใส่


ประวัติการแก้ไข
2015-07-15 06:08:24
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-15 06:06:18 By : NewbiePHP
 


 

No. 15



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


ทีนี้กดที่ปุ่มเพิ่มแล้ว ไม่มีอะไรเกิดขึ้นเลย

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

        Try
            Dim cmd As New OleDbCommand
            If Not con.State = ConnectionState.Open Then
                'open connection if it is not yet open
                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 txtna2.Text = "" Then
            MessageBox.Show("กรุณาเลือกวันเดือนปี")
            Me.txtna2.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.SelectedItem & ",'" & 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_num='" & "'" & _
                                ",out_date1='" & Me.txtdate.Text & "'" & _
                                "WHERE ID_Product='" & Me.semat.Tag
            cmd.ExecuteNonQuery()
        End If


        Catch ex As Exception

        End Try


    End Sub

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-15 09:34:41 By : peemes101
 


 

No. 16



โพสกระทู้ ( 821 )
บทความ ( 0 )



สถานะออฟไลน์


แก้ส่วนท้ายนิดนึงครับ

Catch ex As Exception
msgbox(ex.message)
End Try

บางทีมันอาจ error แต่ไม่บอก
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-15 09:46:23 By : fonfire
 


 

No. 17



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

โค๊ดนี้มันคือไรครับ
Code (VB.NET)
If Me.semat.Tag & "=" Then

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-15 10:10:28 By : lamaka.tor
 


 

No. 18



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


ข้อความขึ้นว่า

Systax error (miss operator) in query expression ‘101ส้ม’

โดย semat.seclectitem เป็นcombobox ซึ่งมีitemให้เลือกได้แก่
101ส้ม
102มะละกอ
103 เงาะ
ซึ่งอยากให้โชว์ในการเลือกแบบนี้

ขณะที่ในฐานข้อมูลคอลัมชื่อ สินค้า มีชนิดข้อมูลเป็น Number
ดังนั้นควรเปลี่ยนเป็นอย่างไร


Code (VB.NET)
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles add.Click

        Try
            Dim cmd As New OleDbCommand
            If Not con.State = ConnectionState.Open Then
                'open connection if it is not yet open
                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

            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_Out_Product(ID,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 & "')"

                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
            RefreshData()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try



    End Sub



ประวัติการแก้ไข
2015-07-15 22:41:51
2015-07-15 22:43:11
2015-07-15 22:51:17
2015-07-16 01:13:49
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-15 22:08:42 By : peemes101
 


 

No. 19

Guest


cmd.CommandText = " INSERT INTO tb_Out_Product(ID,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 & "')"
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-15 23:19:12 By : Mi
 


 

No. 20



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


โอเค ทำตามแล้ว

และขึ้นตอนรันโดยบอกว่า Systax error (miss operator) in query expression ‘ID_Product=’.

Code (VB.NET)
 Try
            Dim cmd As New OleDbCommand
            If Not con.State = ConnectionState.Open Then
                'open connection if it is not yet open
                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

            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_Out_Product(ID,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 & "')"

                cmd.ExecuteNonQuery()
            Else
                'update data in tab
                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
            RefreshData()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try




ประวัติการแก้ไข
2015-07-16 02:09:15
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 00:49:06 By : peemes101
 


 

No. 21



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

" SET ID_Product=" & Me.semat.SelectedItem &
......
.....
" WHERE ID_Product=" & Me.semat.Tag
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 08:31:40 By : lamaka.tor
 


 

No. 22



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


ตอนรัน ขึ้นว่า Systax error (miss operator) in query expression ‘ID_Product=’.
อยู่ดี
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 09:17:27 By : peemes101
 


 

No. 23



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 22 เขียนโดย : peemes101 เมื่อวันที่ 2015-07-16 09:17:27
รายละเอียดของการตอบ ::

ที่ให้ดูคือว่ามันผิดตรงนี้ครับ
" SET ID_Product=" & Me.semat.SelectedItem &
......
.....
" WHERE ID_Product=" & Me.semat.Tag
ลองดูตัวอย่างดูครับ
https://www.thaicreate.com/tutorial/sql-update.html

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 09:42:51 By : lamaka.tor
 


 

No. 24



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


อ่อ ขอโทษที
คือตั้งID ในaccessเป็น autonumber ซึ่งเป็นคอลัมที่1
ดังนั้นในUpdateต้องเขียนมั้ย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 09:49:03 By : peemes101
 


 

No. 25



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 24 เขียนโดย : peemes101 เมื่อวันที่ 2015-07-16 09:49:03
รายละเอียดของการตอบ ::
มองเห็นแล้วนะครับ

มันไม่ได้เกี่ยวกับ autonumber โดยตรงครับ
แค่
เมื่อเรา " WHERE ID_Product=" & Me.semat.Tag
เราก็ไม่ควรที่จะ " SET ID_Product=" & Me.semat.SelectedItem

หรือถ้าเราเปลี่ยนเป็นตัวอื่น

Code (VB.NET)
cmd.CommandText = "Update tb_Out_Product " & _
                               " SET ID_Product=" & Me.semat.SelectedItem &
                               ", out_student='" & Me.txtna1.Text & "'" & _
                               ", out_store='" & Me.txtna2.Text & "'" & _
                               " ,out_date1='" & Me.txtdate.Value.ToShortDateString & "'" & _
                               " WHERE out_num=" & Me.txtnum.Text


", out_num='" & Me.txtnum.Text & "'" & _ ก็ต้องหายไปตามระเบียบครับ
เพราะเราระบุอยู่แล้วว่า " WHERE out_num=" & Me.txtnum.Text

ลองแบบนี้ดูครับ

Code (VB.NET)
If Me.semat.Tag Then
               'add new
               'add data to table

               cmd.CommandText = " INSERT INTO tb_Out_Product(ID,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 tab
               cmd.CommandText = "Update tb_Out_Product " & _
                               ", 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
              
           End If
       cmd.ExecuteNonQuery() 'ย้ายลงมาเพื่อลดการเขียนโค๊ด


ทำบ่อยqจากโค๊ด 5000 บรรทัดอาจจะเหลือแค่ 500 ดูง่ายขึ้นครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 10:14:24 By : lamaka.tor
 


 

No. 26



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


ไม่ได้อ่ะ
ขึ้นว่า syntax error in delete statement
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 10:25:49 By : peemes101
 


 

No. 27



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 26 เขียนโดย : peemes101 เมื่อวันที่ 2015-07-16 10:25:49
รายละเอียดของการตอบ ::
ตอบไม่ได้ครับ ไม่มี SQL delete มาให้ดู 5555

แต่แนะให้ ดู syntex เกี่ยวกับ delete เพราะ จขกท จะตายน้ำตื้นเรื่อง syntex 5555
https://www.google.com/search?q=System.Threading.Thread+return+value&ie=utf-8&oe=utf-8#q=SQL+delete

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 10:32:53 By : lamaka.tor
 


 

No. 28



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


พิมผิด

มันขึ้นว่า


syntax error in UPDATE statement
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 10:36:51 By : peemes101
 


 

No. 29



โพสกระทู้ ( 821 )
บทความ ( 0 )



สถานะออฟไลน์


ใช้ไฟล์ Access ใช่ไหมครับ
เป็นเวอร์ชั่นอะไรเหรอครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 10:38:55 By : fonfire
 


 

No. 30



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 28 เขียนโดย : peemes101 เมื่อวันที่ 2015-07-16 10:36:51
รายละเอียดของการตอบ ::
ขอดู SQL ล่าสุดกับ Error หน่อยครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 10:44:33 By : lamaka.tor
 


 

No. 31



โพสกระทู้ ( 821 )
บทความ ( 0 )



สถานะออฟไลน์


ผมไม่ค่อยชินกับ access น่ะครับ
แต่อยากให้ลองโหลดโปรแกรมที่เอาไว้ติดต่อกับ Access มาลองใช้ดู
และลองพิมพ์คำสั่ง ทดสอบ ก่อน
แล้วค่อยมาแก้ที่ตัวโปรแกรมอีกที
จะได้รู้ว่า คำสั่งที่เราทำมันใช้ได้หรือปล่าว

ลองโหลดโปรแกรมตัวนี้มาใช้ดูครับ
http://download.cnet.com/SQL-Query-Tool-Using-ODBC/3000-10254_4-10057486.html


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 10:51:19 By : fonfire
 


 

No. 32



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 31 เขียนโดย : fonfire เมื่อวันที่ 2015-07-16 10:51:19
รายละเอียดของการตอบ ::
Access มี Query ในตัวอยู่แล้วครับ

https://support.office.com/en-us/article/Examples-of-query-criteria-3197228c-8684-4552-ac03-aba746fb29d8
http://www.gcflearnfree.org/access2013/10
http://www.gcflearnfree.org/access2013/20


ว่าแล้วก็เพิ่งสังเกตเห็นว่า VS 2012 ที่ผมใช้มันทำ datasource wizard เหมือน Access นี่เองมิน่าถึงได้ใช้ง่ายนัก 5555

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 11:02:01 By : lamaka.tor
 


 

No. 33



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบคุณ FONFIRE
ใช้access 2007


และตอบคุณ TOR_CHEMISTRY

มันerror ว่า syntax error in UPDATE statement
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 11:02:06 By : peemes101
 


 

No. 34



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 33 เขียนโดย : peemes101 เมื่อวันที่ 2015-07-16 11:02:06
รายละเอียดของการตอบ ::
ขอดู SQL ล่าสุดกับ Error หน่อยครับ(คืออยากดู detail อ่าครับ ว่ามันว่าไงมั่ง บรรทัดไหน ไร ยังไง ใคร ที่ไหน(มั่วแระ))

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 11:06:46 By : lamaka.tor
 


 

No. 35



โพสกระทู้ ( 821 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 32 เขียนโดย : lamaka.tor เมื่อวันที่ 2015-07-16 11:02:01
รายละเอียดของการตอบ ::
ผมไม่ค่อยชินกับ Wizard อ่ะครับ
ผมว่ามันใช้ยาก 5555

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 11:10:40 By : fonfire
 


 

No. 36



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


ทำไมขอดูsql ล่ะ ใช้access 2007
นี้เป็นโค้ดล่าสุด ที่เกิดerror
Code (VB.NET)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles add.Click

        Try
            Dim cmd As New OleDbCommand
            If Not con.State = ConnectionState.Open Then
                'open connection if it is not yet open
                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

            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_Out_Product(ID,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 tab

                cmd.CommandText = "Update tb_Out_Product " & _
                                ", out_num='" & Me.txtnum.Text & "'" & _
                                ", out_student='" & Me.txtna1.Text & "'" & _
                                ", out_store='" & Me.txtna2.Text & "'" & _
                                " ,out_date='" & Me.txtdate.Value.ToShortDateString & "'" & _
                                " WHERE ID_Product=" & Me.semat.Tag

            End If
            cmd.ExecuteNonQuery()
            RefreshData()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try



    End Sub

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 11:13:34 By : peemes101
 


 

No. 37



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 36 เขียนโดย : peemes101 เมื่อวันที่ 2015-07-16 11:13:34
รายละเอียดของการตอบ ::
ข้าน้อยสมควรตาย

เป็นความผิดผมเองครับที่ลืมใส่ Set ใน SQL

Code (VB.NET)
 cmd.CommandText = "Update tb_Out_Product " & _
                                "Set out_num='" & Me.txtnum.Text & "'" & _
                                ", out_student='" & Me.txtna1.Text & "'" & _
                                ", out_store='" & Me.txtna2.Text & "'" & _
                                " ,out_date='" & Me.txtdate.Value.ToShortDateString & "'" & _
                                " WHERE ID_Product=" & Me.semat.Tag



รูปแบบ

Code (SQL)
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;


สมองบ้านๆอย่างผมก็ไม่ถนัด SQL ซะด้วย 5555 ส่วนใหญ่ให้ datasource wizard จัดการ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 11:23:52 By : lamaka.tor
 


 

No. 38



โพสกระทู้ ( 216 )
บทความ ( 0 )



สถานะออฟไลน์


ยัง error ว่า syntax error in UPDATE statement อยู่ดี
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 11:27:15 By : peemes101
 


 

No. 39

Guest


บรรทัดสุดท้าย " WHERE ID_Product=" & Me.semat.Tag น่าจะ " WHERE ID_Product= ' " & Me.semat.Tag & " '; "
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 11:33:01 By : Mi
 


 

No. 40



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 35 เขียนโดย : fonfire เมื่อวันที่ 2015-07-16 11:10:40
รายละเอียดของการตอบ ::
ยากตอนแก้ครับเพราะมันผูกกับระบบแต่ถ้าเราเข้าใจมันเราจะไม่ปวดหัวกับ SQL syntex เลย
สามารถสร้าง syntext ที่ซับซ้อนได้โดยไม่ต้องมีความรู้ด้าน syntext SQL เลย

ผมสามารถ Insert Update Delete หรือ สร้าง parameter ได้โดยไม่รู้แม้กระทั่งโครงสร้างพื้นฐานของมันครับ
ฤกไฟกฟไ


syntext SQL ก็มีนะครับว่างๆผมก็เข้าไปแก้เล่นเหมือนกัน


ประวัติการแก้ไข
2015-07-16 11:42:53
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 11:38:26 By : lamaka.tor
 


 

No. 41



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 38 เขียนโดย : peemes101 เมื่อวันที่ 2015-07-16 11:27:15
รายละเอียดของการตอบ ::
syntax error แจ้งว่า error ตรงจุดไหนของ Update ครับ

มันต้องใส่แบบนี้ป่าวอ่า

Code (VB.NET)
" WHERE ID_Product='" & Me.semat.Tag & "'"

หรือไม่ก็เป็นที่ datatype ครับ

ผมมีรูปแบบมานำเสนอครับ

http://stackoverflow.com/questions/24432558/vb-net-updating-sql-database-command

ไม่เคยเห็นแบบที่เอา Insert มารวมกับ Update แบบนี้เลย 555อยากรู้มันใช้ได้จริงป่าว
และ
http://stackoverflow.com/questions/25498037/vb-net-problem-with-sql-update-command



ลองสละเวลาซัก 10 นาที เพิ่ม datasource wizard มาแล้วลองใช้งานดูครับ
ปัญหาที่คุณแก้มาตั้นนานนี้จะสามารถแก้ไขได้โดยพริบตา

https://www.google.com/search?q=datasource+wizard&source=lnms&tbm=isch&sa=X&ved=0CAcQ_AUoAWoVChMI8c_l6u7exgIV0EqOCh1UtgeS&biw=1440&bih=766

ขออภัยที่ต้องลิ้งค์ยาวแบบนี้เพราะรีบไปกินข้าว 5555
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-07-16 12:01:07 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขึ้นerror tว่า he select statement includes a reserved word or an argument name that is misspelled or missing ตรง da.Fill(dt) ช่วยดูให้หน่อย
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 03
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 อัตราราคา คลิกที่นี่