i has create system registration that use vb.net 2008 & accessdatabase (oledb connection)

i set ID as primary key,when i insert new ID but if ID already in database i will get error cz data duplicates..so anyone know any code that will promp mesej like this "Data already in data base, please insert ID corectly" if data already in accessdatabase...


just select id from database..if id key already saved in database then give an error message..

what u men..do i need use select statment...

Why not make the ID field an auto number .

what u men..do i need use select statment...

Yes.. before insert your data, you need to search the ID in database..
if Id exist in database then show an error message..

can i put select statment with insert statment in same button..

when id in database not same data succesful insert, if same i get mesej & get focus() on id.text
can u help me, i hve try mny time but i still dont how to combine 2 statment...


Using the select statement you need to check if the ID already exist.

If not --insert it.
If already exist---try a new ID.

this my insert code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim conn As New OleDbConnection("provider=microsoft.jet.OleDb.4.0;Data Source=" & Application.StartupPath & "\mydatabase.mdb;Jet OLEDB:Database Password=armada;")

        Dim conAccess As OleDb.OleDbConnection
        conAccess = New OleDb.OleDbConnection


        If id.Text = "" Then
            MessageBox.Show("Please fill id Number!!", "System Error", MessageBoxButtons.OK)

        ElseIf _contactIC = 0 Then

            sql = "insert into information (id)" & "values ('" & id.Text & "')"

            Dim Command As New OleDbCommand(sql, conn)


            MessageBox.Show("Registration Complete.", "MESEJ", MessageBoxButtons.OK)


        End If

this my select code

            Dim strsql As String

            strsql = "SELECT * from information WHERE id = '" & id.Text & "' "


            Dim cmd As New OleDbCommand(strsql, conAccess)
            Dim objreader As OleDbDataReader = cmd.ExecuteReader

            id.Text = objreader("id")
            MessageBox.Show("data already in database = '" & txtc.Text & "'", "MESEJ", MessageBoxButtons.OK)

        Catch ex As Exception
        End Try

how to combine it..

i hve solved my problem..thanz...

Great..Don't Forget to mark this thread as solved.