If MessageBox.Show("คุณต้องการบันทึกรายการเบิกทั้งหมด ใช่หรือไม่ ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then Exit Sub
strsql = "INSERT INTO GoodsDisbursiment_Detail (dis_id,type_id,type_id_sub,re_id_detail,name_re_m,state) VALUES (@dis_id,@type_id,@type_id_sub,@re_id_detail,@name_re_m,@state)"
For i As Integer = 0 To DataGridView1.RowCount - 1
If Not DataGridView1.Rows(i).IsNewRow Then
connectdb()
cm = New SqlCommand(strsql, cn)
With cm
If DataGridView1.Rows(i).Cells(0).Value IsNot Nothing Then
.Parameters.Add(New SqlParameter("@state", SqlDbType.Int).Value = 1)
End If
.Parameters.Add(New SqlParameter("@dis_id", DataGridView1.Rows(i).Cells(1).Value))
.Parameters.Add(New SqlParameter("@re_id_detail", DataGridView1.Rows(i).Cells(2).Value))
.Parameters.Add(New SqlParameter("@name_re_m", DataGridView1.Rows(i).Cells(3).Value))
.Parameters.Add(New SqlParameter("@type_id", DataGridView1.Rows(i).Cells(4).Value))
.Parameters.Add(New SqlParameter("@type_id_sub", DataGridView1.Rows(i).Cells(5).Value))
End With
cm.ExecuteNonQuery()
cm.Parameters.Clear()
closedb()
End If
Next
MessageBox.Show("บันทึกรายการเบิก เรียบร้อยแล้ว", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Dispose()
ไม่ทราบว่าผมควรแก้ไขจุดไหนดีครับ
Tag : .NET, Ms SQL Server 2005, VS 2005 (.NET 2.x)
If MessageBox.Show("คุณต้องการบันทึกรายการเบิกทั้งหมด ใช่หรือไม่ ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then Exit Sub
strsql = "INSERT INTO GoodsDisbursiment_Detail (dis_id,type_id,type_id_sub,re_id_detail,name_re_m,state) VALUES (@dis_id,@type_id,@type_id_sub,@re_id_detail,@name_re_m,@state)"
For i As Integer = 0 To DataGridView1.RowCount - 1
If Not DataGridView1.Rows(i).IsNewRow Then
connectdb()
cm = New SqlCommand(strsql, cn)
With cm
.Parameters.Add(New SqlParameter("@dis_id", DataGridView1.Rows(i).Cells(1).Value))
.Parameters.Add(New SqlParameter("@re_id_detail", DataGridView1.Rows(i).Cells(2).Value))
.Parameters.Add(New SqlParameter("@name_re_m", DataGridView1.Rows(i).Cells(3).Value))
.Parameters.Add(New SqlParameter("@type_id", DataGridView1.Rows(i).Cells(4).Value))
.Parameters.Add(New SqlParameter("@type_id_sub", DataGridView1.Rows(i).Cells(5).Value))
If DataGridView1.Rows(i).Cells(0).Value IsNot Nothing Then
.Parameters.Add(New SqlParameter("@state", SqlDbType.Int).Value = 1)
Else
.Parameters.Add(New SqlParameter("@state", SqlDbType.Int).Value = 0)
End If
End With
cm.ExecuteNonQuery()
cm.Parameters.Clear()
closedb()
End If
Next
MessageBox.Show("บันทึกรายการเบิก เรียบร้อยแล้ว", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Dispose()