dr223
March 30th, 2009, 06:44 AM
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
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