ช่วยแก้ปุ่มเพิ่มรายการให้ทีคะ ติดมาเป็นอาทิตย์แล้ว

มันไม่ได้ Error อะไรหรอกนะคะ Runผ่าน เล่นได้ แต่กดปุ่มแล้วมันเด้งว่า เกิดข้อผิดพลาด...(ตามที่กำหนดในMessageBox) ข้อมูลก็ไม่ขึ้นใน ListView เลย รบกวนทีนะคะ

Private Function CheckList() As Boolean
        Check = False
        strSQL = "SELECT * FROM Sale_Detail WHERE(sale_no = " & CInt(lblS_ID.Text) & " AND pro_no = '" & txtP_ID.Text & "')"
        adapter = New SqlDataAdapter(strSQL, Conn)
        adapter.Fill(ds, "Sale_Detail")
        If ds.Tables("Sale_Detail").Rows.Count <> 0 Then
            Return True
            ds.Tables("Sale_Detail").Clear()
        Else
            Return False
        End If
    End Function

Private Function CheckDataAdd() As Boolean
        Check = False
        If txtPrice.Text = "" Or txtQty.Text = "" Or lblTotal.Text = "" Then
            MessageBox.Show("กรุณากรอกข้อมูลให้ครบ", "ข้อมูลไม่ครบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Return False
        Else
            Return True
        End If
    End Function

Private Sub cmdAddList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddList.Click
        On Error GoTo errDup
        Dim comSave As New SqlCommand
        If CheckDataAdd() = True Then
            If CheckList() = True Then
                strSQL = "UPDATE Sale_Detail SET amount = (amount + " & CInt(txtQty.Text) & ") WHERE(sale_no = " & CInt(lblS_ID.Text) & " AND pro_no = '" & txtP_ID.Text & "')"
                With comSave
                    .CommandType = CommandType.Text
                    .CommandText = strSQL
                    .Connection = Conn
                    .ExecuteNonQuery()
                End With
            Else
                strSQL = "INSERT INTO Sale_Detail(sale_no,pro_no,sale_price,amount) VALUES(@sale_no,@pro_no,@sale_price,@amount)"
                With comSave
                    .Parameters.Clear()
                    .Parameters.Add("@sale_no", SqlDbType.Int).Value = lblS_ID.Text
                    .Parameters.Add("@pro_no", SqlDbType.Text).Value = txtP_ID.Text
                    .Parameters.Add("@sale_price", SqlDbType.Float).Value = txtPrice.Text
                    .Parameters.Add("@amount", SqlDbType.Int).Value = txtQty.Text

                    .CommandType = CommandType.Text
                    .CommandText = strSQL
                    .Connection = Conn
                    .ExecuteNonQuery()
                End With
            End If

            Dim i As Integer = 0
            Dim lvi As ListViewItem
            Dim tmpProductno As Integer = 0
            For i = 0 To Sale_ListView.Items.Count - 1
                tmpProductno = CInt(Sale_ListView.Items(i).SubItems(0).Text)
                If CInt(txtP_ID.Text.Trim()) = tmpProductno Then
                    MessageBox.Show("เลือกรหัสสินค้าซ้ำกัน กรุณาเลือกใหม่", "Warning!!!", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    ClearProductData()
                    txtP_ID.Focus()
                    txtP_ID.SelectAll()
                    Exit Sub
                End If
            Next
            Dim anyData() As String
            anyData = New String() { _
            txtP_ID.Text, _
            lblName.Text, _
            txtQty.Text, _
            txtPrice.Text, _
            lblTotal.Text}
            lvi = New ListViewItem(anyData)
            Sale_ListView.Items.Add(lvi)
            NetTotal()
            ClearProductData()

            txtP_ID.Focus()
        End If
        Exit Sub
errDup:
        MessageBox.Show("เกิดข้อผิดพลาด กรณาตรวจสอบข้อมูลอีกครั้ง   " , "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Exit Sub
    End Sub

ส่วนที่ผิด คิดว่าอยู่ใน Function CheckList คะ เพราะเป็นคำสั่งที่ใช้กับDataGridView แต่หน้าจอเราใช้ ListView ซึ่งไม่รู้ว่าจะแก้ยังไงดี
พอเอา Funtion CheckList ออก ก็มีข้อมูลขึ้นใน ListView แต่ไม่เพิ่มในฐานข้อมูล รบกวนช่วยแก้ให้ทีนะคะ TT

แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่