|
-
Sep 30th, 2003, 08:34 PM
#1
Thread Starter
Lively Member
Dont wan insert duplicate record into database
Hi, How do i prevent user to insert duplicate record in my database? I need to check whether there is any staffNo same in the database, how do i go abt the codes? Can u pls help mi, n give mi some sample codes?
Below are my codes for e inserting of new record.
Private Sub addStaff()
' Validate form values.
If Not IsValidForm() Then
Exit Sub
End If
Dim cnSQL As SqlConnection
Dim cmSQL As SqlCommand
Dim strSQL As String
Try
strSQL = "INSERT INTO StaffInfo(SurName, Name, StaffNo, Designation, Department, ExtNo, Email) VALUES ('" + txtSur.Text + " ','" + txtName.Text + "','" + txtStaffNo.Text + "','" + txtDes.Text + "','" + txtDep.Text + "','" + txtExt.Text + "', '" + txtEmail.Text + "')"
cnSQL = New SqlConnection(ConnectionString)
cnSQL.Open()
cmSQL = New SqlCommand(strSQL, cnSQL)
'Execute query
cmSQL.ExecuteNonQuery()
' Close and Clean up objects
cnSQL.Close()
cmSQL.Dispose()
cnSQL.Dispose()
Catch Exp As SqlException
MsgBox(Exp.Message, MsgBoxStyle.Critical, "SQL Error")
Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
End Try
MessageBox.Show(Me, "Your record is saved!", "Record Saved", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Me.Close()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|