|
-
March 30th, 2009, 06:44 AM
#1
Insert statement
Hallo,
I have the following insert into statement. What I want to do is insert the values to gprdsql.TblOracleNos if TxtOracleNo is not empty,therefore if a user logs on and fill the textbox the values are saved to the table. However, if the oracle number exists in gprdsql.TblOracleNos (i.e, the values ) it should not insert the values, presently it creates the same record again with same values (when the save button is clicked) and this creates duplication. Even if a user changes any other field on the form and clicks save button the record is saved again.
Any help is highly appreciated.. Thanks
If TxtOracleNo.Text <> "" Then
Try
query = "INSERT INTO gprdsql.TblOracleNos (Prac_no, Prac_eid, Pay_method, Oracle_no) VALUES ('" & _
TxtPracNo.Text & "', '" & _
TxtPracEid.Text & "', '" & _
CmbPayMethod.Text & "', '" & _
TxtOracleNo.Text & "')"
"Select Prac_no, Prac_eid, Pay_method, Oracle_no From gprdsql.TblOracleNos WHERE not exists Oracle_no"
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "GCPM")
End Try
End If
-
March 30th, 2009, 09:16 AM
#2
Re: Insert statement
Hi dr223,
Not sure if I am understanding your post correctly. You want it to stop inserting if the txtOracleNo.text field is already filled in or if the entire row is already inserted?
Why not clear the form fields after the insert is complete?
-
March 30th, 2009, 11:12 AM
#3
Re: Insert statement
You could of course do a select first and check to see if you get any results and issue the insert only if the result of the select is empty.
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
|