Private Sub btnUpdateMember_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateMember.Click
If (Not IsDataComplete()) Or txtMemberID.Text = "" Then
Exit Sub
End If
Dim c As DialogResult = MessageBox.Show("ต้องการแก้ไขข้อมูลจริงหรือไม่?", "ยืนยันการแก้ไข", MessageBoxButtons.OKCancel)
If c = DialogResult.OK Then
sql = "UPDATE Member SET"
If Not (txtEmail.Text = "") Then
sql &= "(Member_Name, Member_IDcard, Member_Address, Member_Province, Member_Zipcode, Member_Gender, Member_Marital_Status, Member_Birthday, Member_Occupation, Member_Phone, Member_Email, Apply_Date)"
sql &= "VALUES(@Name, @IDcard, @Address, @Province, @Zipcode, @Gender, @Marital, @Birthday, @Occupation, @Phone, @Email, @Apply)"
Else
sql &= "(Member_Name, Member_IDcard, Member_Address, Member_Province, Member_Zipcode, Member_Gender, Member_Marital_Status, Member_Birthday, Member_Occupation, Member_Phone, Apply_Date)"
sql &= "VALUES(@Name, @IDcard, @Address, @Province, @Zipcode, @Gender, @Marital, @Birthday, @Occupation, @Phone, @Apply)"
End If
sql &= "WHERE Member_ID = @ID"
AddParameters(sql)
If command.ExecuteNonQuery() = 1 Then
MessageBox.Show("ระบบทำการบันทึกข้อมูลเรียบร้อยแล้ว")
UpdateBinding()
Else
MessageBox.Show("เกิดข้อผิดพลาด ไม่สามาถบันทึกข้อมูลได้")
End If
Else
Exit Sub
End If
End Sub
Private Sub AddParameters(ByVal sql As String)
command.Parameters.Clear()
command.CommandText = sql
command.Parameters.AddWithValue("ID", txtMemberID.Text)
command.Parameters.AddWithValue("Name", txtName.Text)
command.Parameters.AddWithValue("IDcard", txtIdcardNo.Text)
command.Parameters.AddWithValue("Address", txtAddress.Text)
command.Parameters.AddWithValue("Province", cbProvince.Text)
command.Parameters.AddWithValue("Zipcode", txtZipCode.Text)
command.Parameters.AddWithValue("Gender", cbGender.Text)
command.Parameters.AddWithValue("Marital", cbStatus.Text)
command.Parameters.AddWithValue("Birthday", dtBirthday.Value)
command.Parameters.AddWithValue("Occupation", cbOccupation.Text)
command.Parameters.AddWithValue("Phone", txtPhone.Text)
command.Parameters.AddWithValue("Email", txtEmail.Text)
command.Parameters.AddWithValue("Apply", dtMemberIn.Value)
End Sub
Incorrect syntax near '('. ไม่ทราบว่าเป็นเพราะอะไรค่ะ
มันขึ้นเออตรง If command.ExecuteNonQuery() = 1 Then ค่ะ
Tag : .NET, Ms SQL Server 2005, VS 2010 (.NET 4.x)