Datareader

How To Use A Datareader Against An Ms Access In C# Net

Page 1 of 1

1 Replies - 5921 Views - Last Post: 12 January 2009 - 02:47 AM Rate Topic: -----

#1 aavachar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-January 09

Datareader

Post icon  Posted 12 January 2009 - 02:03 AM

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 ?
Is This A Good Question/Topic? 0
  • +

Replies To: Datareader

#2 djjeavons  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 44
  • Joined: 09-January 09

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.

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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1