Thursday, April 10, 2008

Data Access in .NET using C#

Page 3 - Data Access in .NET using C#: Part 1: "Data Access in .NET using C#: Part 1 - The DataReader Object"

Live example...

protected void Page_Load(object sender, EventArgs e)
{
string connectionString = "provider=Microsoft.Jet.OLEDB.4.0;data source=c:\\sites\\Single15\\visli\\database\\Olddb.mdb";
OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);
OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();
myOleDbCommand.CommandText = "SELECT * from DetailUrl";
myOleDbConnection.Open();
OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();
myOleDbDataReader.Read();
// dbReader = myOleDbDataReader.Read();
while (myOleDbDataReader.Read())
{
Response.Write(myOleDbDataReader["urlno"]);
Response.Write("
");
}
myOleDbDataReader.Close();
myOleDbConnection.Close();
}

No comments: