Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim tr As SqlTransaction = con.BeginTransaction
For i As Integer = 0 To DataGridView1.RowCount - 1
Dim cm As New SqlCommand("insert into tblbbk1 (keydate,tranid,proid,proname,box,trancost,bill,amount,typeid,zone) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j)", con, tr)
With cm
.Parameters.AddWithValue("@a", dtp.Value.ToString("MM/dd/yyyy"))
.Parameters.AddWithValue("@b", cb1.SelectedValue)
.Parameters.AddWithValue("@c", DataGridView1.Rows(i).Cells(0))
.Parameters.AddWithValue("@d", DataGridView1.Rows(i).Cells(1))
.Parameters.AddWithValue("@e", DataGridView1.Rows(i).Cells(2))
.Parameters.AddWithValue("@f", DataGridView1.Rows(i).Cells(3))
.Parameters.AddWithValue("@g", txt6.Text)
.Parameters.AddWithValue("@h", DataGridView1.Rows(i).Cells(4))
.Parameters.AddWithValue("@i", ty.Text)
.Parameters.AddWithValue("@j", tz.Text)
.ExecuteNonQuery()
End With
Next
tr.Commit()
MessageBox.Show("บันทึกการแก้ไขข้อมูลเรียบร้อยแล้ว", "Database", MessageBoxButtons.OK)
DataGridView1.Rows.Clear()
End Using
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim bs As BindingSource = DataGridView1.DataSource ' จะ Error ถ้าไม่ได้ใช้ BindingSource เป็น DataSource ในตอนแรก
Dim tr As SqlTransaction = con.BeginTransaction
Try
For i As Integer = 0 To DataGridView1.RowCount - 1
Dim cm As New SqlCommand("insert into tblbbk1 (keydate,tranid,proid,proname,box,trancost,bill,amount,typeid,zone) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j)", con, tr)
With cm
.Parameters.AddWithValue("@a", dtp.Value.ToString("MM/dd/yyyy"))
.Parameters.AddWithValue("@b", cb1.SelectedValue)
.Parameters.AddWithValue("@c", bs.List(i)("proid"))
.Parameters.AddWithValue("@d", bs.List(i)("proname"))
.Parameters.AddWithValue("@e", bs.List(i)("box"))
.Parameters.AddWithValue("@f", bs.List(i)("trancost"))
.Parameters.AddWithValue("@g", txt6.Text)
.Parameters.AddWithValue("@h", bs.List(i)("amount"))
.Parameters.AddWithValue("@i", ty.Text)
.Parameters.AddWithValue("@j", tz.Text)
.ExecuteNonQuery()
End With
Next
tr.Commit()
MessageBox.Show("บันทึกการแก้ไขข้อมูลเรียบร้อยแล้ว", "Database", MessageBoxButtons.OK)
DataGridView1.Rows.Clear()
Catch ex As Exception
tr.Rollback() ' ถ้าจะใช้ SqlTransaction ก็ควรจะมี tr.Rollback() เพื่อให้ทำงานได้เต็มรูปแบบ
MessageBox.Show(ex.Message)
Finally
tr.Dispose
End Try
End Using
End Sub
Private Sub butsup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butsup.Click
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim bs As BindingSource = DataGridView1.DataSource 'จะ Error ถ้าไม่ได้ใช้ BindingSource เป็น DataSource ในตอนแรก
Dim tr As SqlTransaction = con.BeginTransaction
Try
For i As Integer = 0 To DataGridView1.RowCount - 1
Dim cm As New SqlCommand("insert into tblbbk1 (keydate,tranid,proid,proname,box,trancost,bill,amount,typeid,zone) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j)", con, tr)
With cm
.Parameters.AddWithValue("@a", dtp.Value.ToString("MM/dd/yyyy"))
.Parameters.AddWithValue("@b", cb1.SelectedValue)
.Parameters.AddWithValue("@c", bs.List(i)("proid"))
.Parameters.AddWithValue("@d", bs.List(i)("proname"))
.Parameters.AddWithValue("@e", bs.List(i)("box"))
.Parameters.AddWithValue("@f", bs.List(i)("trancost"))
.Parameters.AddWithValue("@g", txt6.Text)
.Parameters.AddWithValue("@h", bs.List(i)("amount"))
.Parameters.AddWithValue("@i", ty.Text)
.Parameters.AddWithValue("@j", tz.Text)
.ExecuteNonQuery()
End With
Next
tr.Commit()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "Database", MessageBoxButtons.OK)
DataGridView1.Rows.Clear()
'หากโปรแกรม Error ให้เเสดงข้อมความของ Debug โดยใช้ Catch . . . as Exception
Catch ex As Exception
tr.Rollback()
MessageBox.Show(ex.Message)
Finally
tr.Dispose()
End Try
End Using
End Sub
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim bs As BindingSource = DataGridView1.DataSource 'จะ Error ถ้าไม่ได้ใช้ BindingSource เป็น DataSource ในตอนแรก
Dim tr As SqlTransaction = con.BeginTransaction
Try
For i As Integer = 0 To DataGridView1.RowCount - 1
Dim cm As New SqlCommand("insert into tblbbk1 (keydate,tranid,proid,proname,box,trancost,bill,amount,typeid,zone) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j)", con, tr)
With cm
.Parameters.AddWithValue("@a", dtp.Value.ToString("MM/dd/yyyy"))
.Parameters.AddWithValue("@b", cb1.SelectedValue)
.Parameters.AddWithValue("@c", bs.List(i)("proid"))
.Parameters.AddWithValue("@d", bs.List(i)("proname"))
.Parameters.AddWithValue("@e", bs.List(i)("box"))
.Parameters.AddWithValue("@f", bs.List(i)("trancost"))
.Parameters.AddWithValue("@g", txt6.Text)
.Parameters.AddWithValue("@h", bs.List(i)("amount"))
.Parameters.AddWithValue("@i", ty.Text)
.Parameters.AddWithValue("@j", tz.Text)
.ExecuteNonQuery()
End With
Next
tr.Commit()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "Database", MessageBoxButtons.OK)
DataGridView1.Rows.Clear()
'หากโปรแกรม Error ให้เเสดงข้อมความของ Debug โดยใช้ Catch . . . as Exception
Catch ex As Exception
tr.Rollback()
MessageBox.Show(ex.Message)
Finally
tr.Dispose()
End Try
End Using
End Sub
พี่วินครับ จากโค๊ดข้างบนนี้ เวลากด บันทึก rate เเล้วมัน show message เเบบนี้คับ
ลองเปลี่ยน
For i As Integer = 0 To DataGridView1.RowCount - 1
เป็น
For i As Integer = 0 To bs.Count - 1
Code (VB.NET)
Private Sub butsup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butsup.Click
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim bs As BindingSource = DataGridView1.DataSource 'จะ Error ถ้าไม่ได้ใช้ BindingSource เป็น DataSource ในตอนแรก
Dim tr As SqlTransaction = con.BeginTransaction
Try
For i As Integer = 0 To bs.Count - 1
Dim cm As New SqlCommand("insert into tblbbk1 (keydate,tranid,proid,proname,box,trancost,bill,amount,typeid,zone) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j)", con, tr)
With cm
.Parameters.AddWithValue("@a", dtp.Value.ToString("MM/dd/yyyy"))
.Parameters.AddWithValue("@b", cb1.SelectedValue)
.Parameters.AddWithValue("@c", bs.List(i)("proid"))
.Parameters.AddWithValue("@d", bs.List(i)("proname"))
.Parameters.AddWithValue("@e", bs.List(i)("box"))
.Parameters.AddWithValue("@f", bs.List(i)("trancost"))
.Parameters.AddWithValue("@g", txt6.Text)
.Parameters.AddWithValue("@h", bs.List(i)("amount"))
.Parameters.AddWithValue("@i", ty.Text)
.Parameters.AddWithValue("@j", tz.Text)
.ExecuteNonQuery()
End With
Next
tr.Commit()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "Database", MessageBoxButtons.OK)
DataGridView1.Rows.Clear()
'หากโปรแกรม Error ให้เเสดงข้อมความของ Debug โดยใช้ Catch . . . as Exception
Catch ex As Exception
tr.Rollback()
MessageBox.Show(ex.Message)
Finally
tr.Dispose()
End Try
End Using
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("DataSource: " & DataGridView1.DataSource.GetType.ToString)
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim bs As BindingSource = DataGridView1.DataSource ' จะ Error ถ้าไม่ได้ใช้ BindingSource เป็น DataSource ในตอนแรก
Dim tr As SqlTransaction = con.BeginTransaction
Try
For i As Integer = 0 To DataGridView1.RowCount - 1
Dim cm As New SqlCommand("insert into tblbbk1 (keydate,tranid,proid,proname,box,trancost,bill,amount,typeid,zone) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j)", con, tr)
With cm
.Parameters.AddWithValue("@a", dtp.Value.ToString("MM/dd/yyyy"))
.Parameters.AddWithValue("@b", cb1.SelectedValue)
.Parameters.AddWithValue("@c", bs.List(i)("proid"))
.Parameters.AddWithValue("@d", bs.List(i)("proname"))
.Parameters.AddWithValue("@e", bs.List(i)("box"))
.Parameters.AddWithValue("@f", bs.List(i)("trancost"))
.Parameters.AddWithValue("@g", txt6.Text)
.Parameters.AddWithValue("@h", bs.List(i)("amount"))
.Parameters.AddWithValue("@i", ty.Text)
.Parameters.AddWithValue("@j", tz.Text)
.ExecuteNonQuery()
End With
Next
tr.Commit()
MessageBox.Show("บันทึกการแก้ไขข้อมูลเรียบร้อยแล้ว", "Database", MessageBoxButtons.OK)
DataGridView1.Rows.Clear()
Catch ex As Exception
tr.Rollback() ' ถ้าจะใช้ SqlTransaction ก็ควรจะมี tr.Rollback() เพื่อให้ทำงานได้เต็มรูปแบบ
MessageBox.Show(ex.Message)
Finally
tr.Dispose
End Try
End Using
End Sub
Private Sub butre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butre.Click
If MessageBox.Show("คุณต้องการเรียกข้อมูลใช่หรือไม่?", "Database", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
'****การดึงข้อมูลมาโชว์ใน DataGrid****'
DataGridView1.Show()
lv.Hide()
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim sql As String = "select * from tblsum where keydate ='" & dtp.Value.ToString("MM/dd/yyyy") & "'and tranid ='" & cb1.SelectedValue & "'"
Dim cmd As SqlCommand = New SqlCommand(sql, con)
Dim dr As SqlDataReader = cmd.ExecuteReader
Dim dt = New DataTable
If dr.HasRows Then
Dim r As Integer = 0
While dr.Read
With DataGridView1
r = .RowCount - 1
.Rows.Add()
.Rows(r).Cells(0).Value = dr.Item(2)
.Rows(r).Cells(1).Value = dr.Item(3)
.Rows(r).Cells(2).Value = dr.Item(4)
End With
End While
End If
End Using
End If
DataGridView1.Focus()
มีส่วนไหมคับที่เวลาผมดึงข้อมูลมา จะมี Record ที่ว่างอยู่สุดท้ายเสมอ อะคับ ส่วนนี้จะทำให้ Error ได้เป่าคับ
เเล้วจะสามารถทำให้เวลาดึงข้อมูลมา ไม่เอา record ที่เป็นค่า ว่างได้เป่าคับ ให้พอดีกับข้อมูลที่ดึงมาเลยคับ
โค๊ด ดึงข้อมูล
Code (VB.NET)
f MessageBox.Show("คุณต้องการเรียกข้อมูลใช่หรือไม่?", "Database", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
'****การดึงข้อมูลมาโชว์ใน DataGrid****'
DataGridView1.Show()
lv.Hide()
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim sql As String = "select * from tblsum where keydate ='" & dtp.Value.ToString("MM/dd/yyyy") & "'and tranid ='" & cb1.SelectedValue & "'"
Dim cmd As SqlCommand = New SqlCommand(sql, con)
Dim dr As SqlDataReader = cmd.ExecuteReader
Dim dt = New DataTable
If dr.HasRows Then
Dim r As Integer = 0
While dr.Read
With DataGridView1
r = .RowCount - 1
.Rows.Add()
.Rows(r).Cells(0).Value = dr.Item(2)
.Rows(r).Cells(1).Value = dr.Item(3)
.Rows(r).Cells(2).Value = dr.Item(4)
End With
End While
End If
End Using
End If
DataGridView1.Focus()
If MessageBox.Show("คุณต้องการเรียกข้อมูลใช่หรือไม่?", "Database", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
'****การดึงข้อมูลมาโชว์ใน DataGrid****'
DataGridView1.Show()
lv.Hide()
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim sql As String = "select * from tblsum where keydate ='" & dtp.Value.ToString("MM/dd/yyyy") & "'and tranid ='" & cb1.SelectedValue & "'"
Dim cmd As SqlCommand = New SqlCommand(sql, con)
Dim dr As SqlDataReader = cmd.ExecuteReader
Dim dt = New DataTable
If dr.HasRows Then
Dim r As Integer = 0
While dr.Read
With DataGridView1
r = .RowCount - 1
.Rows.Add()
.Rows(r).Cells(0).Value = dr.Item(2)
.Rows(r).Cells(1).Value = dr.Item(3)
.Rows(r).Cells(2).Value = dr.Item(4)
End With
End While
End If
End Using
End If
DataGridView1.Focus()
Private Sub butsup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butsup.Click
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
'Dim bs As BindingSource = DataGridView1.DataSource 'จะ Error ถ้าไม่ได้ใช้ BindingSource เป็น DataSource ในตอนแรก
Dim tr As SqlTransaction = con.BeginTransaction
'Try
For i As Integer = 0 To DataGridView1.RowCount - 1
Dim cm As New SqlCommand("insert into tblbbk1 (keydate,tranid,proid,proname,box,trancost,bill,amount,typeid,zone) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j)", con, tr)
With cm
.Parameters.AddWithValue("@a", dtp.Value.ToString("MM/dd/yyyy"))
.Parameters.AddWithValue("@b", cb1.SelectedValue)
.Parameters.AddWithValue("@c", DataGridView1.Rows(i).Cells(0).Value)
.Parameters.AddWithValue("@d", DataGridView1.Rows(i).Cells(1).Value)
.Parameters.AddWithValue("@e", DataGridView1.Rows(i).Cells(2).Value)
.Parameters.AddWithValue("@f", DataGridView1.Rows(i).Cells(3).Value)
.Parameters.AddWithValue("@g", txt6.Text)
.Parameters.AddWithValue("@h", DataGridView1.Rows(i).Cells(4).Value)
.Parameters.AddWithValue("@i", ty.Text)
.Parameters.AddWithValue("@j", tz.Text)
.ExecuteNonQuery()
End With
Next
tr.Commit()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "Database", MessageBoxButtons.OK)
DataGridView1.Rows.Clear()
'' ''หากโปรแกรม Error ให้เเสดงข้อมความของ Debug โดยใช้ Catch . . . as Exception
'Catch ex As Exception
' tr.Rollback()
' MessageBox.Show(ex.Message)
'Finally
' tr.Dispose()
'End Try
End Using
End Sub
ผมใช้ Code นี้คับในการคำนวน
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Dim i As Integer
For i = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(i).Cells(4).Value = DataGridView1.Rows(i).Cells(3).Value * DataGridView1.Rows(i).Cells(2).Value
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim tr As SqlTransaction = con.BeginTransaction
For i As Integer = 0 To DataGridView1.RowCount - 1
Dim cm As New SqlCommand("insert into tblbbk1 (keydate,tranid,proid,proname,box,trancost,bill,amount,typeid,zone) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j)", con, tr)
With cm
.Parameters.AddWithValue("@a", dtp.Value.ToString("MM/dd/yyyy"))
.Parameters.AddWithValue("@b", cb1.SelectedValue)
.Parameters.AddWithValue("@c", DataGridView1.Rows(i).Cells(0))
.Parameters.AddWithValue("@d", DataGridView1.Rows(i).Cells(1))
.Parameters.AddWithValue("@e", DataGridView1.Rows(i).Cells(2))
.Parameters.AddWithValue("@f", DataGridView1.Rows(i).Cells(3))
.Parameters.AddWithValue("@g", txt6.Text)
.Parameters.AddWithValue("@h", DataGridView1.Rows(i).Cells(4))
.Parameters.AddWithValue("@i", ty.Text)
.Parameters.AddWithValue("@j", tz.Text)
.ExecuteNonQuery()
End With
Next
tr.Commit()
MessageBox.Show("บันทึกการแก้ไขข้อมูลเรียบร้อยแล้ว", "Database", MessageBoxButtons.OK)
DataGridView1.Rows.Clear()
End Using
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim tr As SqlTransaction = con.BeginTransaction
' ส่วนของการสร้าง Parameters ไว้ก่อน For Loop
Dim cm As New SqlCommand("insert into tblbbk1 (keydate,tranid,proid,bill,typeid,zone) values (@a,@b,@proid,@g,@i,@j)", con, tr)
With cm
.Parameters.AddWithValue("@a", dtp.Value.ToString("MM/dd/yyyy"))
.Parameters.AddWithValue("@b", cb1.SelectedValue)
.Parameters.Add("@proid", SqlDbType.NVarChar,2) ' แนะนำให้ Add Parameters ด้วยวิธีนี้ การ AddWithValue อาจทำให้ระบบตีความหมายของชนิดตัวแปรไม่ตรงกับที่ต้องการ
.Parameters.AddWithValue("@g", txt6.Text)
.Parameters.AddWithValue("@i", ty.Text)
.Parameters.AddWithValue("@j", tz.Text)
End With
For i As Integer = 0 To DataGridView1.RowCount - 1
If Not DataGridView1.Rows(i).IsNewRow Then
' Parameters ใดที่ไม่มีการแก้ไขข้อมูล ก็ไม่จำเป็นต้องใส่ใน For Loop
cm.Parameters("@proid").Value = DataGridView1.Rows(i).Cells(0).Value
cm.ExecuteNonQuery()
End If
Next
tr.Commit()
MessageBox.Show("บันทึกการแก้ไขข้อมูลเรียบร้อยแล้ว", "Database", MessageBoxButtons.OK)
DataGridView1.Rows.Clear()
End Using
End Sub
Private Sub butsup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butsup.Click
Using con As New SqlConnection("data source=tiger;initial catalog=transport;uid=sa;pwd=47222420322")
con.Open()
Dim tr As SqlTransaction = con.BeginTransaction
' ส่วนของการสร้าง Parameters ไว้ก่อน For Loop
Dim cm As New SqlCommand("insert into tblbbk1 (keydate,tranid,proid,proname,box,trancost,bill,amount,typeid,zone) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j)", con, tr)
With cm
.Parameters.AddWithValue("@a", dtp.Value.ToString("MM/dd/yyyy"))
.Parameters.AddWithValue("@b", cb1.SelectedValue)
.Parameters.Add("@c", SqlDbType.NVarChar, 2) ' แนะนำให้ Add Parameters ด้วยวิธีนี้ การ AddWithValue อาจทำให้ระบบตีความหมายของชนิดตัวแปรไม่ตรงกับที่ต้องการ
.Parameters.Add("@d", SqlDbType.NVarChar, 50)
.Parameters.Add("@e", SqlDbType.Int)
.Parameters.Add("@f", SqlDbType.NVarChar, 20)
.Parameters.AddWithValue("@g", txt6.Text)
.Parameters.Add("@h", SqlDbType.Float)
.Parameters.AddWithValue("@i", ty.Text)
.Parameters.AddWithValue("@j", tz.Text)
End With
Try
For i As Integer = 0 To DataGridView1.RowCount - 1
If Not DataGridView1.Rows(i).IsNewRow Then
' Parameters ใดที่ไม่มีการแก้ไขข้อมูล ก็ไม่จำเป็นต้องใส่ใน For Loop
cm.Parameters("@c").Value = DataGridView1.Rows(i).Cells(0).Value
cm.Parameters("@d").Value = DataGridView1.Rows(i).Cells(1).Value
cm.Parameters("@e").Value = DataGridView1.Rows(i).Cells(2).Value
cm.Parameters("@f").Value = DataGridView1.Rows(i).Cells(3).Value
cm.Parameters("@h").Value = DataGridView1.Rows(i).Cells(4).Value
cm.ExecuteNonQuery()
End If
Next
tr.Commit()
If MessageBox.Show("คุณต้องการบันทึกข้อมูลใช่หรือไม่?", "Database", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
MessageBox.Show("บันทึกข้อมูลเรียบร้อยเเล้ว", "Database", MessageBoxButtons.OK, MessageBoxIcon.Information)
DataGridView1.Rows.Clear()
DataGridView1.Hide()
lv.Show()
butsup.Enabled = False
butre.Enabled = False
End If
Catch ex As Exception
tr.Rollback() ' ถ้าจะใช้ SqlTransaction ก็ควรจะมี tr.Rollback() เพื่อให้ทำงานได้เต็มรูปแบบ
MessageBox.Show(ex.Message)
Finally
tr.Dispose()
End Try
End Using
butre.Enabled = True
butadd.Enabled = True
butprint.Enabled = True
buts.Enabled = True
End Sub