i want to access to fields from table & places its value in textboxs
How To Use A Datareader Against An Ms Access In C# Net ?
DatareaderHow To Use A Datareader Against An Ms Access In C# Net
Page 1 of 1
1 Replies - 4647 Views - Last Post: 12 January 2009 - 02:47 AM
Replies To: Datareader
#2
Re: Datareader
Posted 12 January 2009 - 02:47 AM
Hi
The following simple example demonstrates how to connect to the Access database and to execute a standard select statement. It then uses the DataReader to read the first entry in the returned results and assigns the value to a Text Box.
HTH
The following simple example demonstrates how to connect to the Access database and to execute a standard select statement. It then uses the DataReader to read the first entry in the returned results and assigns the value to a Text Box.
//Modify path to database and select statement accordingly.
using (OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=c:\temp\test.mdb"))
{
using (OleDbCommand command = new OleDbCommand("Select CompanyName From Companies", connection))
{
//Open the connection, execute the reader, populate a text box with data from reader and close the connection.
connection.Open();
using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
textBox1.Text = reader["CompanyName"].ToString();
break;
}
}
connection.Close();
}
}
HTH
This post has been edited by djjeavons: 12 January 2009 - 02:48 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|