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...

anyone..

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...

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

Edited 5 Years Ago by Jx_Man: n/a

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...

Edited 5 Years Ago by arezz09: n/a

Yes.

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)
            id.Focus()

       
        ElseIf _contactIC = 0 Then

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

            conn.Open()
            Dim Command As New OleDbCommand(sql, conn)
            Command.ExecuteNonQuery()

            conn.Close()

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

            Me.Close()

        End If

this my select code

Try
            Dim strsql As String

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

            conAccess.Open()

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

            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..

Edited 5 Years Ago by arezz09: n/a

This question has already been answered. Start a new discussion instead.