CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    192

    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

  2. #2
    Join Date
    Mar 2007
    Posts
    56

    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?

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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
  •  





Click Here to Expand Forum to Full Width

Featured