 |
|
ช่วยดูให้หน่อยคะ ไม่รู้ว่าผิดตรงไหน คือจะ Insert ข้อมูลจาก DataGridView ลง ฐานข้อมูลนะคะ |
|
 |
|
|
 |
 |
|
dgv.Rows(i).Cells(0).Value ไม่มีค่าครับ
|
 |
 |
 |
 |
Date :
2010-07-10 13:13:14 |
By :
Programmer ด้อยปัญญา สำนัก ทองเสียง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หูวววว เป็น error ที่แปลกที่สุดที่เคยเห็นมาเลยค่ะ insert แต่ออก message prepare error งืมๆๆ จดๆๆ
|
 |
 |
 |
 |
Date :
2010-07-10 13:18:20 |
By :
blurEyes |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วต้องแก้ไขยังไงอะคะ หนูก็ ใส่ค่าเข้าไปก่อนที่จะทำการ Insert แล้วอะ
นี้อะคะ หนู พอกดปุ่ม button ก็จะทำการ Insert ตาม code ที่เอามาให้ดูอะคะ แล้วทำไมมันถึงแบบไม่ไม่ค่าอะค่ะ

|
 |
 |
 |
 |
Date :
2010-07-10 19:25:24 |
By :
ง่าๆงงๆคะ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
datagridview-->datatable-->sqldataadapter-->sql server
พอจะเก็ตไหม
|
 |
 |
 |
 |
Date :
2010-07-10 22:47:35 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่เก็ตอะคะ พี่ tungman
ช่วยอธิบายละเอียด หรือ ยกตัวอย่างหน่อยจะได้ไหมคะ
|
 |
 |
 |
 |
Date :
2010-07-10 23:59:02 |
By :
ง่าๆงงๆคะ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ง่า พี่ tungman ไม่ช่วยหนูเลยอะ
|
 |
 |
 |
 |
Date :
2010-07-12 18:54:31 |
By :
ง่าๆงงๆคะ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
DataGridView --> DataTable
Code (VB.NET)
Dim Dt As New DataTable()
Dim Dv As DataView = DirectCast(dgv.DataSource, DataView)
Dt = Dv.ToTable()
DataTable --> SqlDataAdapter --> MS SQL Server
Code (VB.NET)
Dim CommandString As String = "Insert Into [tbl_PromotionProduct] (IdPP,PromotionName) VALUES (@IdPP, @PromotionName)"
Dim Command As New SqlCommand(CommandString, conn)
Command.Parameters.Add("@IdPP", SqlDbType.NVarChar, 50, "IdPP") 'IdPP คือชื่อ column ใน Dt อาจจะไม่ตรงเพราะผมไม่รู้ว่าคุณกำหนดไว้ชื่ออะไร
Command.Parameters.Add("@PromotionName", SqlDbType.Char, 1, "PromotionName") 'PromotionName คือชื่อ column ใน Dt อาจจะไม่ตรงเพราะผมไม่รู้ว่าคุณกำหนดไว้ชื่ออะไร
Dim DataAdapter As New SqlDataAdapter()
DataAdapter.InsertCommand = Command
DataAdapter.Update(Dt)
|
 |
 |
 |
 |
Date :
2010-07-12 19:22:19 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Dim Dt As New DataTable()
Dim Dv As DataView = DirectCast(dgv.DataSource, DataView)
Dt = Dv.ToTable ' error ตรงนี้
Dim CommandString As String = "Insert Into [tbl_paymentProduct] (Id,IdEmp) VALUES (@Id, @IdEmp)"
Dim Command As New SqlCommand(CommandString, conn)
Command.Parameters.Add("@Id", SqlDbType.NVarChar, 50, "Id")
Command.Parameters.Add("@IdEmp", SqlDbType.NVarChar, 50, "IdEmp")
Dim DataAdapter As New SqlDataAdapter()
DataAdapter.InsertCommand = Command
DataAdapter.Update(Dt)
มัน error ว่างี้อะค่ะ

|
 |
 |
 |
 |
Date :
2010-07-14 22:23:10 |
By :
ง่าๆงงๆคะ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดู
Code (VB.NET)
Dt = Dv.Table.Copy
|
 |
 |
 |
 |
Date :
2010-07-14 22:32:18 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|