sql = "insert into f_ree(reno,recode,reitem,recodedoc,renamedoc,reinv,redate,remark,recodeitem,renameitem,reqty,reunit) values(@reno,@recode,@reitem,@recodedoc,@renamedoc,@reinv,@redate,@remark,@recodeitem,@renameitem,@reqty,@reunit)"
For i As Integer = 0 To Datare.RowCount - 1
If Not Datare.Rows(i).IsNewRow Then
cmd = New System.Data.SqlClient.SqlCommand(sql, cn)
With cmd
.Parameters.Add(New SqlParameter("@reno", nore.Text))
.Parameters.Add(New SqlParameter("@recode", Comkey.Text))
.Parameters.Add(New SqlParameter("@reitem", Sup2.Text))
.Parameters.Add(New SqlParameter("@recodedoc", sup3.Text))
.Parameters.Add(New SqlParameter("@renamedoc", sup4.Text))
.Parameters.Add(New SqlParameter("@reinv", sup5.Text))
.Parameters.Add(New SqlParameter("@redate", sup6.Text))
.Parameters.Add(New SqlParameter("@remark", sup7.Text))
.Parameters.Add(New SqlParameter("@recodeitem", Datare.Rows(i).Cells(0).Value))
.Parameters.Add(New SqlParameter("@renameitem", Datare.Rows(i).Cells(1).Value))
.Parameters.Add(New SqlParameter("@reqty", Datare.Rows(i).Cells(2).Value))
.Parameters.Add(New SqlParameter("@reunit", Datare.Rows(i).Cells(3).Value))
End With
cmd.ExecuteNonQuery()
'End If
'Next
End If
Next
MessageBox.Show("บันทึกข้อมูลแล้ว")
cn.Close()
Tag : .NET, Ms SQL Server 2014, VS 2015 (.NET 4.x)