Search
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Articles Author
Wed, 01-Apr-2015 Authors
All Time Authors
Sheonarayan
39800
Sourav.Kayal
39750
Niladri.Biswas
33350

Latest members | More ...


(Statistics delayed by 5 minutes)
Ads
 Article

Connecting with MS Access 2007 database from C# Windows application

ttarakarajesh-8732
Posted by under C# category on for Beginner level | Points: 250 | Views : 45633 red flag
If you found plagiarised (copied) or inappropriate content,
please let us know the original source along with your correct email id (to communicate) for further action.
This article explains to us , how to connect with MS Access 2007 database from C# Windows application.

 

Introduction

First of all I would like to say thanks to all the readers. In this article, I am going to show you how to connect with MS Access 2007 database from C#.NET windows application.  Design our window as follows.

Form Design




Code


private void btnGetData_Click(object sender, EventArgs e)
{
string
conStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C\TestTable.accdb; Persist Security Info=False;";


OleDbConnection
con = new OleDbConnection(conStr);

try
{

con.Open();

OleDbCommand
cmd = new OleDbCommand("Select Sname,Sal from Tarak where ID="+txtSNO.Text, con);

OleDbDataReader
dr = cmd.ExecuteReader();

 

if
(dr.Read())

{

 
txtName.Text = dr["SName"].ToString();

 
txtSal.Text ="$"+ dr["sal"].ToString();

}

}

catch
(Exception ex)

{

lblMessage.Visible = true;

lblMessage.Text = ex.Message;

}

}


Conclusion


I hope this article helps for connecting with MS Access Database.

Happy Programming!!!!


Thanks & Regards,
Tarak

Page copy protected against web site content infringement by Copyscape
About the Author

ttarakarajesh-8732

Full Name: Taraka Rajesh Talagadadeevi
Member Level: Starter
Member Status: Member
Member Since: 1/28/2011 4:38:05 AM
Country: India

Login to vote for this post.
Share this to:

Bookmark It

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)