รบกวนด้วยค่ะ มัน error Conversion failed when converting the varchar value '' to data type int. ต้องแก้ตรงไหนคะ ขอบคุณมากๆนะคะ
มันไม่ Save ลงฐานข้อมูลค่ะ (SQL 2008)
โค้ดทั้งหมดค่ะ
Private Sub btn_qtvsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_qtvsave.Click
sql = "insert into quotation (c_name ,c_contact ,prod_name ,prod_maker ,prod_price ,qtv_qty ,qtv_unit ,qtv_pricetotal ,qtv_remark ,qtv_full_id ,date_qtv)values "
Dim i As Integer = Me.listviewqtv.Items.Count - 1
For j As Integer = 0 To i
Dim c_name As String = Me.listviewqtv.Items(j).SubItems(8).Text
Dim c_contact As String = Me.listviewqtv.Items(j).SubItems(9).Text
Dim prod_name As String = Me.listviewqtv.Items(j).SubItems(2).Text
Dim prod_maker As String = Me.listviewqtv.Items(j).SubItems(1).Text
Dim prod_price As Integer = Me.listviewqtv.Items(j).SubItems(5).Text
Dim qtv_qty As Integer = Me.listviewqtv.Items(j).SubItems(3).Text
Dim qtv_unit As String = Me.listviewqtv.Items(j).SubItems(4).Text
Dim qtv_pricetotal As Integer = Me.listviewqtv.Items(j).SubItems(6).Text
Dim qtv_remark As String = Me.listviewqtv.Items(j).SubItems(7).Text
Dim date_qtv As String = Date.Now.Year & "/" & Date.Now.Month & "/" & Date.Now.Day
If j = i Then
sql &= String.Format(" ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')", Me.lbl_qtvcus_name.Text, c_name, c_contact, prod_name, prod_maker, prod_price, qtv_qty, qtv_unit, qtv_pricetotal, qtv_remark, date_qtv)
Else
sql &= String.Format(" ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}'),", Me.lbl_qtvcus_name.Text, c_name, c_contact, prod_name, prod_maker, prod_price, qtv_qty, qtv_unit, qtv_pricetotal, qtv_remark, date_qtv)
End If
Next
cmd = New SqlClient.SqlCommand(sql, cn)
If cmd.ExecuteNonQuery = 0 Then
MsgBox("ไม่สามารถบันทึกได้")
Else
sql = "insert into quotation_detail ((qtv_full_id ,date_qtv ,c_name ,prod_name ,prod_price,qtv_pricetotal) values (@qtv_full_id ,@date_qtv ,@c_name ,@prod_name ,@prod_price ,@qtv_pricetotal)"
cmd = New SqlClient.SqlCommand(sql, cn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("qtv_full_id", Me.lbl_qtv_id.Text)
cmd.Parameters.AddWithValue("date_qtv", Me.lbl_qtv_date.Text)
cmd.Parameters.AddWithValue("c_name", Me.lbl_qtvcus_name.Text)
cmd.Parameters.AddWithValue("prod_name", Me.lbl_qtvprod_name.Text)
cmd.Parameters.AddWithValue("prod_price", Me.lbl_qtvprod_price.Text)
cmd.Parameters.AddWithValue("qtv_pricetotal", Me.txt_total.Text)
End If
If cmd.ExecuteNonQuery = 0 Then
MsgBox("ไม่สามารถบันทึกได้")
Else
MsgBox("บันทึกสำเร็จ")
End If
End Sub
รบกวนด้วยค่ะ มัน error Conversion failed when converting the varchar value '' to data type int. ต้องแก้ตรงไหนคะ/VB
มันไม่ Save ลงฐานข้อมูลค่ะ (SQL 2008)
โค้ดทั้งหมดค่ะ
Private Sub btn_qtvsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_qtvsave.Click
sql = "insert into quotation (c_name ,c_contact ,prod_name ,prod_maker ,prod_price ,qtv_qty ,qtv_unit ,qtv_pricetotal ,qtv_remark ,qtv_full_id ,date_qtv)values "
Dim i As Integer = Me.listviewqtv.Items.Count - 1
For j As Integer = 0 To i
Dim c_name As String = Me.listviewqtv.Items(j).SubItems(8).Text
Dim c_contact As String = Me.listviewqtv.Items(j).SubItems(9).Text
Dim prod_name As String = Me.listviewqtv.Items(j).SubItems(2).Text
Dim prod_maker As String = Me.listviewqtv.Items(j).SubItems(1).Text
Dim prod_price As Integer = Me.listviewqtv.Items(j).SubItems(5).Text
Dim qtv_qty As Integer = Me.listviewqtv.Items(j).SubItems(3).Text
Dim qtv_unit As String = Me.listviewqtv.Items(j).SubItems(4).Text
Dim qtv_pricetotal As Integer = Me.listviewqtv.Items(j).SubItems(6).Text
Dim qtv_remark As String = Me.listviewqtv.Items(j).SubItems(7).Text
Dim date_qtv As String = Date.Now.Year & "/" & Date.Now.Month & "/" & Date.Now.Day
If j = i Then
sql &= String.Format(" ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')", Me.lbl_qtvcus_name.Text, c_name, c_contact, prod_name, prod_maker, prod_price, qtv_qty, qtv_unit, qtv_pricetotal, qtv_remark, date_qtv)
Else
sql &= String.Format(" ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}'),", Me.lbl_qtvcus_name.Text, c_name, c_contact, prod_name, prod_maker, prod_price, qtv_qty, qtv_unit, qtv_pricetotal, qtv_remark, date_qtv)
End If
Next
cmd = New SqlClient.SqlCommand(sql, cn)
If cmd.ExecuteNonQuery = 0 Then
MsgBox("ไม่สามารถบันทึกได้")
Else
sql = "insert into quotation_detail ((qtv_full_id ,date_qtv ,c_name ,prod_name ,prod_price,qtv_pricetotal) values (@qtv_full_id ,@date_qtv ,@c_name ,@prod_name ,@prod_price ,@qtv_pricetotal)"
cmd = New SqlClient.SqlCommand(sql, cn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("qtv_full_id", Me.lbl_qtv_id.Text)
cmd.Parameters.AddWithValue("date_qtv", Me.lbl_qtv_date.Text)
cmd.Parameters.AddWithValue("c_name", Me.lbl_qtvcus_name.Text)
cmd.Parameters.AddWithValue("prod_name", Me.lbl_qtvprod_name.Text)
cmd.Parameters.AddWithValue("prod_price", Me.lbl_qtvprod_price.Text)
cmd.Parameters.AddWithValue("qtv_pricetotal", Me.txt_total.Text)
End If
If cmd.ExecuteNonQuery = 0 Then
MsgBox("ไม่สามารถบันทึกได้")
Else
MsgBox("บันทึกสำเร็จ")
End If
End Sub