comm = New SqlClient.SqlCommand("Insert Into [tbl_PromotionProduct] (IdPP,PromotionName) VALUES (@IdPP,@PromotionName)", conn)
For i As Integer = 0 To dgv.Rows.Count - 1
comm.Parameters.Clear()
comm.Parameters.Add("@IdPP", SqlDbType.NVarChar).Value = dgv.Rows(i).Cells(0).Value
comm.Parameters.Add("@PromotionName", SqlDbType.Char).Value = dgv.Rows(i).Cells(1).Value
comm.ExecuteNonQuery()
Next
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
No. 8
Guest
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)