 |
|
Code
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
If txtcustomerid.Text.Trim() = "" Then
MessageBox.Show("กรุณาป้อนรหัสลูกค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtcustomerid.Focus()
Exit Sub
End If
If txtname.Text.Trim() = "" Then
MessageBox.Show("กรุณาป้อนชื่อลูกค้าก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtname.Focus()
Exit Sub
End If
If MessageBox.Show("คุณต้องการเพิ่มลูกค้าใหม่ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
tr = Conn.BeginTransaction() 'ติดตรงนี้ Invalid operation. The connection is closed.
Try
sb.Remove(0, sb.Length)
sb.Append("INSERT INTO member (FullName,Sex,Birthday,Address,Tel,Email,DateTackout)")
sb.Append(" VALUES (@FullName, @Sex, @Birthday, @Address, @Tel, @Email, @DateTackout)")
Dim sqlAdd As String
sqlAdd = sb.ToString()
With com
.CommandText = sqlAdd
.CommandType = CommandType.Text
.Connection = Conn
.Transaction = tr
.Parameters.Clear()
.Parameters.Add("@FullName", OleDb.OleDbType.VarChar).Value = txtname.Text.Trim()
.Parameters.Add("@Sex", OleDb.OleDbType.VarChar).Value = txtsex.Text.Trim()
.Parameters.Add("@Birthday", OleDb.OleDbType.VarChar).Value = mtbbirthday.Text.Trim()
.Parameters.Add("@Address", OleDb.OleDbType.VarChar).Value = txtaddress.Text.Trim()
.Parameters.Add("@Tel", OleDb.OleDbType.VarChar).Value = txttel.Text.Trim()
.Parameters.Add("@Email", OleDb.OleDbType.VarChar).Value = txtmail.Text.Trim()
.Parameters.Add("@DateTackout", OleDb.OleDbType.VarChar).Value = mtbday.Text.Trim()
.ExecuteNonQuery()
End With
tr.Commit()
MessageBox.Show("เพิ่มลูกค้าใหม่ เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
ClearAllData()
ShowData()
FormatDgvCustomerList()
Catch ex As Exception
MessageBox.Show("คุณป้อนรหัสลูกค้าซ้ำ !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
tr.Rollback()
End Try
End If
txtcustomerid.Focus()
End Sub
หรือว่าใครมีวิธี ไรแนะนำบ้าง ขอบคุณคับ
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2009-09-28 17:30:22 |
By :
meraiwa |
View :
1878 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |