For i As Integer = 0 To ServicebilldetailDataGridView1.Rows.Count - 1
If ServicebilldetailDataGridView1.Rows(i).Cells(5).Value IsNot Nothing Then
Dim id As String = ServicebilldetailDataGridView1.Rows(i).Cells(1).Value.ToString()
Dim strselectinsert As String = "รบกวนเขียนตรงนี้หน่อยครับ"
com.CommandType = CommandType.Text
com.CommandText = strselectinsert
com.Connection = con
com.ExecuteNonQuery()
MsgBox("OK")
End If
Next
เขียนมาหลายรอบแล้วไม่ผ่านจริงๆครับ
Tag : .NET, VS 2010 (.NET 4.x), VS 2012 (.NET 4.x)
เห้อผลสรุปได้แล้วครับ ผมเขียนถูกแต่แรกแล้วแหละ แต่ SQL SERVER เครื่อง PC ผมมีปัญหา
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Servicebilldetail_Servicebill". The conflict occurred in database "Carcare", table "dbo.Servicebill", column 'Servicebill_id'.
The statement has been terminated.
บ้าอะไรไม่รุ้เนี้ย
แต่เอาไปรันใน Notebook OK ครับทำงานได้แล้ว
Code (VB.NET)
If ServicebilldetailDataGridView1.Rows(i).Cells(5).Value IsNot Nothing Then
Dim id As String = ServicebilldetailDataGridView1.Rows(i).Cells(5).Value.ToString()
Dim strselectDEL As String = "insert into Servicebilldetail (Servicebilldetail_id,ServicebillMenu_id,Servicebill_id,Servicebilldetai_name,Servicebilldetai_price) values ('" + ServicebilldetailDataGridView1.Rows(i).Cells(0).Value.ToString + "','" _
+ ServicebilldetailDataGridView1.Rows(i).Cells(2).Value.ToString + "','" + ServicebilldetailDataGridView1.Rows(i).Cells(1).Value.ToString + "','" + ServicebilldetailDataGridView1.Rows(i).Cells(3).Value.ToString + "','" + ServicebilldetailDataGridView1.Rows(i).Cells(4).Value.ToString + "')"
com.CommandType = CommandType.Text
com.CommandText = strselectDEL
com.Connection = con
com.ExecuteNonQuery() '
MsgBox("OK")
End If
Next