 |
|
Code (VB.NET)
sqltr = Conn.BeginTransaction()
Try
sb.Remove(0, sb.Length)
sb.AppendLine("INSERT INTO Customer ( CustomerID,CustomerName,CustomerType,Telephone,Address1)")
sb.AppendLine(" VALUES (@CustomerID, @CustomerName, @CustomerType, @Telephone, @Address1)")
Dim sqlAdd As String
sqlAdd = sb.ToString()
With Com
.CommandType = CommandType.Text
.CommandText = sqlAdd
.Connection = Conn
.Transaction = sqltr
.Parameters.Clear()
.Parameters.Add("@CustomerID", SqlDbType.VarChar).Value = txtCustomerNo.Text.Trim()
.Parameters.Add("@CustomerName", SqlDbType.NVarChar).Value = txtCusName.Text.Trim()
.Parameters.Add("@CustomerType", SqlDbType.NVarChar).Value = txtCustype.Text.Trim()
.Parameters.Add("@Telephone", SqlDbType.NVarChar).Value = txtCusTelephone.Text.Trim()
.Parameters.Add("@Address1", SqlDbType.NVarChar).Value = txtCusAddress.Text.Trim()
.ExecuteNonQuery()
End With
sqltr.Commit()
MessageBox.Show("เพิ่มข้อมูลลูกค้าผู้เช่าใหม่ เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
ClearAllData()
ShowData()
FormatdgvCustomer()
txtCustomerNo.Focus()
Catch ex As Exception
MessageBox.Show(ex.ToString(), "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
sqltr.Rollback()
End Try
ผมสามารถ add ลง database ได้แต่มันจะขึ้น error must declare the scalar variable @CustomerID แล้วทำให้โปรแกรมค้างตลอด
ผมงงทำไม่ได้ซะที ช่วยดูหน่อยนะครับ
Tag : .NET, VB.NET
|
ประวัติการแก้ไข 2011-08-07 16:39:10
|
 |
 |
 |
 |
Date :
2011-08-07 16:36:00 |
By :
mardede |
View :
2081 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |