Hello I'm new to visual basic 2010. I have learned how to search, add new record and it works perfectly but I'm having problem on how to check if the first name, middle name and last name is already exists inside the access database before saving new record. I don't know how to code it please help me.
Here is the self experiment I'm creating and I'm sorry for my bad coding.
Thanks a lot in advanced.
Imports System.Data.OleDb
Public Class Form1
Public connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents\tablename.accdb"
Public conn As New OleDbConnection(connstring)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If conn.State = ConnectionState.Closed Then
conn.Open()
MsgBox("connection is open", vbInformation)
Else
MsgBox("connection is close", vbCritical)
End If
End Sub
Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search.Click
If txtsearch.Text = Nothing Then
MsgBox("nothing to search", vbCritical)
Else
Dim myadapter As New OleDbDataAdapter("SELECT * FROM fullname WHERE ID = " & txtsearch.Text, conn)
Dim mytable As New DataTable
myadapter.Fill(mytable)
If mytable.Rows.Count > 0 Then
Me.txtid.Text = mytable.Rows(0).Item("ID")
Me.txtfname.Text = mytable.Rows(0).Item("fname")
Me.txtmname.Text = mytable.Rows(0).Item("mname")
Me.txtlname.Text = mytable.Rows(0).Item("lname")
Else
MsgBox("No Record Found", vbCritical, "Search")
End If
End If
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
Dim myadapter As New OleDbDataAdapter("INSERT INTO fullname ( fname, mname, lname) VALUES ('" & txtfname.Text & "', '" & txtmname.Text & "', '" & txtlname.Text & "')", conn)
Dim mytable As New DataTable
myadapter.Fill(mytable)
End Sub
End Class
Here is the self experiment I'm creating and I'm sorry for my bad coding.
Thanks a lot in advanced.
Quote:
Imports System.Data.OleDb
Public Class Form1
Public connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents\tablename.accdb"
Public conn As New OleDbConnection(connstring)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If conn.State = ConnectionState.Closed Then
conn.Open()
MsgBox("connection is open", vbInformation)
Else
MsgBox("connection is close", vbCritical)
End If
End Sub
Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search.Click
If txtsearch.Text = Nothing Then
MsgBox("nothing to search", vbCritical)
Else
Dim myadapter As New OleDbDataAdapter("SELECT * FROM fullname WHERE ID = " & txtsearch.Text, conn)
Dim mytable As New DataTable
myadapter.Fill(mytable)
If mytable.Rows.Count > 0 Then
Me.txtid.Text = mytable.Rows(0).Item("ID")
Me.txtfname.Text = mytable.Rows(0).Item("fname")
Me.txtmname.Text = mytable.Rows(0).Item("mname")
Me.txtlname.Text = mytable.Rows(0).Item("lname")
Else
MsgBox("No Record Found", vbCritical, "Search")
End If
End If
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
Dim myadapter As New OleDbDataAdapter("INSERT INTO fullname ( fname, mname, lname) VALUES ('" & txtfname.Text & "', '" & txtmname.Text & "', '" & txtlname.Text & "')", conn)
Dim mytable As New DataTable
myadapter.Fill(mytable)
End Sub
End Class