Sunday, 30 December 2012 13:55

accessing access database in csharp dot net application

Written by 
Rate this item
(0 votes)

access database file is easy to use than sql server
or MySql server databases.for accessing access db
System.Data.OleDb namespace used.following are
steps are needed to use access db in .net
application.

1.first initialize connection -

OleDbConnection conn = new OleDbConnection(@"Provider=
Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|db.mdb;
Jet OLEDB:Database Password=csharp");

2.and then the following example shows rest -

using (DatabaseConnection)
{
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * from dbtable",
conn);
OleDbDataReader reader = cmd.ExecuteReader();
if (reader.HasRows == true)
{
reader.Read();
Label1.Text = reader.GetDateTime(0).ToShortDateString();
}
else
{
Label1.Text = "Unknown";
}}

Read 3137 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.