Plz any one can help me...
i have only one table in an ms access database(2007).that table contain two fields only ID,Name.i want to search that table using ID(primary key) and result should show the name of particular id.
In a vb.net(2008) form i put one text box,one button and one label which show result.And i added the database in project.NOW WANT I HAVE TO DO.......PLEASE HELP ME

Hi!

>>> i added the database in project

How did you add ??? you mean from menu "Data->Add New Data" Source ???
because it makes DataSet bydefault otherwise we need to go with OleDb class to work with it.

yes sir ,i added database by "Data->Add New Data" ,but instead of that want i have to do.plz guide me

Hi!

One approach using LINQ:

Dim ds As New testDataSet()
Dim tblAdapt As New testDataSetTableAdapters.tblATableAdapter()
tblAdapt.Fill(ds.tblA)
If textBox1.Text <> "" OrElse textBox1.Text <> [String].Empty Then ' if ID did not provide
	Dim query = (From d In ds.tblA Where d.ID = Convert.ToInt32(textBox1.Text)d.Text)
	For Each s As [String] In query
		Me.Text = s 'print the value where suitable.
	Next
Else
	MessageBox.Show("Please Enter ID")
End If

You can also parse the "textBox1.Text" for must a numeric datatype. For that "Add Reference" from "Solution Explorer" and under ".Net Tab" select "Microsoft.VisualBasic", then add this line on ".vb file":
Imports Microsoft.VisualBasic

So this line:
If textBox1.Text <> "" OrElse textBox1.Text <> [String].Empty Then

will become:
If textBox1.Text <> "" OrElse textBox1.Text <> [String].Empty And Information.IsNumeric(textBox1.Text) Then

Did you get it ??? OR Still around ???

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.