We help IT Professionals succeed at work.

Duplicate Validation in code(vb)

50 Views
Last Modified: 2015-07-01
How can I check for a record that exists before insert in code behind.

eg

In the below I want to check that the @QUALSCHEMEID exist or not

 Public Sub InsertGCH()

            'If Session("ModeType") = "Insert" Then

            Dim strConnString As String = ConfigurationManager.ConnectionStrings("IrisConnectionString").ConnectionString

            Dim con As New SqlConnection(strConnString)

            Dim cmd As New SqlCommand()

            cmd.CommandType = CommandType.StoredProcedure

            cmd.CommandText = "Insert_REVIEWS_GCH"

            'cmd.Parameters.Add("@TRAINEEID", SqlDbType.NVarChar).Value = Request("TRAINEEID")

            'cmd.Parameters.Add("@POT", SqlDbType.Int).Value = Request("POT")

            cmd.Parameters.Add("@QUALSCHEMEID", SqlDbType.Int).Value = ddlQUALSCHEMEID.SelectedValue.Trim()

            cmd.Parameters.Add("@ReviewID", SqlDbType.Int).Value = Session("REVIEWS")

            cmd.Parameters.Add("@GCH", SqlDbType.NVarChar).Value = txtGCH.Text.Trim()


            cmd.Connection = con



            con.Open()

            cmd.ExecuteNonQuery()




            con.Close()

            con.Dispose()





        End Sub

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Ed

Author

Commented:
Perfect, thanks
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.