Hi
I am new in VB.net. I need urgently help
I am connected to SQL Express database - table.Customer.
I create a "Detail" of the Customer Field on the Form.
The fields are binding with the database table.
When I click the "Add" record, user can type in the Customer Code, Customer Name, Address..etc and Click "Save" it, the datase insert the record or update the record. There is no problem.
Rule: Customer Code cannot be duplicate in the tbl_customer, Customer ID is a Primary Key.
Problem 1:
The problem is that, when the user click the "Save", how do I check whether the Customer Code is found in the table and prompt the message to the user to change the Customer Code. How do I write the code before save the record.
Problem 2
I have create a delete button on the form and prompt the message for user to confirm to delete the record.
This customer table is related to the Order Table. I want to count with the Order_Header Table with this Customer ID. If found, not allowed to delete. If not, delete the record. How do I insert the code to check the other table with the related table?
Hope my problem is clear.
Many thanks.
I am new in VB.net. I need urgently help
I am connected to SQL Express database - table.Customer.
I create a "Detail" of the Customer Field on the Form.
The fields are binding with the database table.
When I click the "Add" record, user can type in the Customer Code, Customer Name, Address..etc and Click "Save" it, the datase insert the record or update the record. There is no problem.
Rule: Customer Code cannot be duplicate in the tbl_customer, Customer ID is a Primary Key.
Problem 1:
The problem is that, when the user click the "Save", how do I check whether the Customer Code is found in the table and prompt the message to the user to change the Customer Code. How do I write the code before save the record.
VB.NET:
Private Sub CustomerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerBindingNavigatorSaveItem.Click
Me.Validate()
Me.CustomerBindingSource.EndEdit()
Me.CustomerTableAdapter.Update(Me.CustomerDataSet)
Me.CustomerDataSet.AcceptChanges()
End Sub
Problem 2
I have create a delete button on the form and prompt the message for user to confirm to delete the record.
This customer table is related to the Order Table. I want to count with the Order_Header Table with this Customer ID. If found, not allowed to delete. If not, delete the record. How do I insert the code to check the other table with the related table?
VB.NET:
Private Sub btn_Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Delete.Click
Dim Response As MsgBoxResult
Response = MsgBox("Do you want to delete this record?", MsgBoxStyle.YesNo, "Message - Delete")
If Response = MsgBoxResult.No Then
Me.btn_Exit.Focus()
Exit Sub
Else
'Delete Record
Me.CustomerBindingSource.RemoveCurrent()
Me.CustomerBindingSource.EndEdit()
Me.CustomerTableAdapter.Update(Me.CustomerDataSet)
Me.CustomerDataSet.AcceptChanges()
Me.Close()
End If
End Sub
Hope my problem is clear.
Many thanks.