Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

how to prevent duplicate entries into mssql database

$
0
0
i have a form that contains a text box to accept varchar(50) type data. Please help me add an additional feature to the existing code that prevents the user from entering duplicate entries.
the code i have so far to store user input is:


Code:

Private Function addInstitute() As Boolean

        Dim cmd As New SqlCommand
        Dim ok As Boolean = False


        cmd.Connection = con
        cmd.CommandText = " INSERT INTO institute(institute_name) VALUES(@inn)"
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("inn", inTxt.Text)
       
        MessageBox.Show("record added")


        Try
            con.Open()
            cmd.ExecuteNonQuery()
            ok = True
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Add failed")
            ok = False
        End Try


        cmd.Dispose()
        con.Close()
        Return ok


    End Function


Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>