 |
|
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_order_detail_material". |
|
 |
|
|
 |
 |
|
Code (VB.NET)
With cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strconn
.Open()
End With
Dim s As String = ""
If status = "add" Then
s = "insert into [order](id_order,id_sup,dateorder,total)"
s &= " values(@id_or,@id_sup,@dateor,@to)"
Else
s = "update [order] set total = @to where id_order = @id_or"
End If
Dim cm As New SqlCommand
With cm
.CommandType = CommandType.Text
.CommandText = s
.Connection = cn
.Parameters.Clear()
.Parameters.Add("@id_or", SqlDbType.NVarChar, 5).Value = id_order.Text
.Parameters.Add("@id_sup", SqlDbType.NVarChar, 6).Value = ComboBox1.SelectedValue
.Parameters.Add("@dateor", SqlDbType.NVarChar, 10).Value = order_date.Text
.Parameters.Add("@to", SqlDbType.Int).Value = CSng(txttotal.Text)
'ขั้นที่ 3 รัน
.ExecuteNonQuery()
End With
For i = 0 To ListView1.Items.Count - 1
Dim s1 As String = ""
s1 = "insert into [order_detail](id_order,id_material,unitorder,unitrub)"
s1 &= "values (@id_or,@id_mat,@unor,@unru)"
Dim cm1 As New SqlCommand
With cm1
.CommandType = CommandType.Text
.CommandText = s1
.Connection = cn
.Parameters.Clear()
.Parameters.Add("@id_or", SqlDbType.NVarChar, 5).Value = id_order.Text
.Parameters.Add("@id_mat", SqlDbType.NVarChar, 3).Value = ListView1.Items(i).SubItems(2).Text
.Parameters.Add("@unor", SqlDbType.Int).Value = ListView1.Items(i).SubItems(4).Text
.Parameters.Add("@unru", SqlDbType.Int).Value = ListView1.Items(i).SubItems(5).Text
.ExecuteNonQuery()
End With
Next
MessageBox.Show("บันทึกข้อมูลเรียบร้อย")
นี้คือโค้ดที่ยังมีปัญหาอ่ะครับ
|
 |
 |
 |
 |
Date :
2012-12-17 20:31:41 |
By :
บี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก Error เหมือนพวก PK (Primary Key) มันซ้ำน่ะครับ
|
 |
 |
 |
 |
Date :
2012-12-18 09:08:09 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องเข้าไปเช็ค table ใน database ดีดีคับ
|
 |
 |
 |
 |
Date :
2012-12-18 10:57:43 |
By :
buildbuilt |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันจะซ้ำตรง id_order หรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2012-12-18 19:03:17 |
By :
บี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|