Hello,

I do the simple project using VB.net 2008 to link with MS Access 2007. I have two textbox which is data for ID and Fullname.

txtID.Text = ID
txtFullname.Text = Fullname
Button1 = Search

In MS Access
My data for ID : 1,2 & 3
and My data for Fullname : John, Peter & Mike

The problem I facing now is when I type '1' in txtID, output was appear in txtFullname. But when I type '2' in txtID, the output is not appear in txtFullname.

Only ID 1 I can call. BUt another ID can't.

PLease Help me.

This is my code :

Imports System.Data.OleDb
Public Class Form1

Dim con As New OleDbConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles MyBase.Load
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\sample.accdb"
con.Open()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)   Handles Button1.Click
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter

da = New OleDbDataAdapter("SELECT * FROM phonebookTable", con)
da.Fill(dt)

txtID.Text = dt.Rows(0).Item(0)
txtFullname.Text = dt.Rows(1).Item(0)

con.Close()
End Sub
End Class

I'm confused, your code doesn't match your description. You aren't searching by ID, you're using select all without a where filter so its returning everything. And then your placing the first result of the first two returned rows into txtID and txtFullName. SO when you click the button you should see 1 and 2 displayed. Am I missing something?
You also appear to be opening your connection on form load and only closing it when the button is clicked. You want your connections to be open for as short a as time as possible, instead of leaving it open waiting for you to use it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.