Test your technical skills online, appear in Virtual Interview and be ready for job!
Twitter Twitter LinkedIn YouTube Google
Be Interview ready ! | Search
Make friends on DotNetFunda.com and expand your network!
Winners

Win Prizes

Announcements
Like us on Facebook
Sponsor
Top Articles Author
Wed, 23-Apr-2014 Authors
All Time Authors
Sourav.Kayal
39750
Sheonarayan
34800
Niladri.Biswas
33350

Latest members | More ...


(Statistics delayed by 5 minutes)
Ads

Connecting with MS Access 2007 database from C# Windows application

Ttarakarajesh@gmail.com
Posted by under C# category on for Beginner level | Points: 250 | Views : 36688 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
Found interesting? Add this to:




About the Author

Ttarakarajesh@gmail.com

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.

Comments or Responses


Login to post response.

Comments / Responses
Select text & click toolbar to format. Formatting appears in viewmode only. HTML Tags are not allowed.
Bold Italic Underline Paragraph Title Code  Link 
 Wait ... Processing ..... please wait.

Comment using Facebook