|
![](/images/resource/spacer.gif) |
|
เพิ่มค่าจาก GridView ลง ฐานข้อมูลทีละหลายๆค่าไม่ได้อ่ะครับ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
Code
cmd.CommandType = CommandType.Text;
string ID = txtid.Text;
cmd.CommandText = " insert into Order_1 (Date,ID,com_name) values('" + dtp1.Value.ToString("MM-dd-yyyy") + "','" + ID + "','" + cboCom.SelectedValue + "')";
cmd.Connection = Conn;
cmd.ExecuteNonQuery();
;
foreach (DataGridViewRow gvr in GridView1.Rows)
{
cmd.CommandText = "insert into Order_detail(Order_id,Pro_id,Order_Size,Order_Qualty,Order_Price)values ('" +txtid.Text +"','" + gvr.Cells[0].Value + "','" + gvr.Cells[1].Value + "','" + gvr.Cells[2].Value+ "','" + gvr.Cells[3].Value + "')";
cmd.Connection = Conn;
cmd.ExecuteNonQuery();
}
MessageBox.Show("ทำรายการสำเร็จ");
Tag : .NET, Ms SQL Server 2012, C#
![](/images/adv.jpg?v=1001)
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-07-21 20:00:20 |
By :
oceanplanet |
View :
835 |
Reply :
5 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ไม่ได้คืออะไร? ลอง Debug หรือไม่ก็เอา Error ออกมาดู
Code (VB.NET)
Try
cmd.CommandType = CommandType.Text;
string ID = txtid.Text;
cmd.CommandText = " insert into Order_1 (Date,ID,com_name) values('" + dtp1.Value.ToString("MM-dd-yyyy") + "','" + ID + "','" + cboCom.SelectedValue + "')";
cmd.Connection = Conn;
cmd.ExecuteNonQuery();
;
foreach (DataGridViewRow gvr in GridView1.Rows)
{
cmd.CommandText = "insert into Order_detail(Order_id,Pro_id,Order_Size,Order_Qualty,Order_Price)values ('" +txtid.Text +"','" + gvr.Cells[0].Value + "','" + gvr.Cells[1].Value + "','" + gvr.Cells[2].Value+ "','" + gvr.Cells[3].Value + "')";
cmd.Connection = Conn;
cmd.ExecuteNonQuery();
}
MessageBox.Show("ทำรายการสำเร็จ");
Catch ex As Exception
MsgBox(ex.Message)
End Try
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-07-22 08:02:37 |
By :
ipstarone |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ขอโทษ จากข้างต้นด้วยครับ
Code(C#)
![Error Error](https://www.thaicreate.com/upload/stock/20150722092639.jpg?v=1001)
|
ประวัติการแก้ไข 2015-07-22 09:46:56
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-07-22 09:27:55 |
By :
oceanplanet |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
Order_id กำหนดเป็น Is Identity ไว้รึป่าวครับ
ถ้าใช่ txtid.Text อย่างเดียวคงไม่พอ เพราะมันต้องเพิ่มขึ้นเรื่อยๆ
แต่งงยุจุด
Code (VB.NET)
string ID = txtid.Text;
cmd.CommandText = " insert into Order_1 (Date,ID,com_name) values('" + dtp1.Value.ToString("MM-dd-yyyy") + "','" + ID + "','" + cboCom.SelectedValue + "')";
cmd.CommandText = "insert into Order_detail(Order_id,Pro_id,Order_Size,Order_Qualty,Order_Price)values ('" +txtid.Text +"','" + gvr.Cells[0].Value + "','" + gvr.Cells[1].Value + "','" + gvr.Cells[2].Value+ "','" + gvr.Cells[3].Value + "')";
ทำไม ID ใน Order_1 กับ Order_id ถึงเป็นตัวเดียวกันละครับ(txtid.Text)
ที่ถามเพราะสงสัยว่า Order_id กำหนดเป็น Is Identity ไว้
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-07-22 09:53:59 |
By :
lamaka.tor |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ใน เทเบิล Order_Detail มี Order_id เป็น Primary key รึป่าวครับ ถ้าใช้ ปรับไม่ให้มันเป็น Primary key ซะ
ดูที่ เออเรอ มัน บอกค่าซ้ำนะครับ ลองดูนะครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-07-22 11:00:47 |
By :
as76157432 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ได้ละครับ ขอบคุณ ทุกคอมเม้น ครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-07-22 12:47:53 |
By :
oceanplanet |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 04
|