SIGN UP MEMBER LOGIN:    
ARTICLE

Simplest program on database access using ADO

Posted by Mahesh Chand Articles | ADO.NET in C# January 01, 2000
Accessing database is pretty simple job using C# and ADO. In this sample code, I access an access database.
Reader Level:

Accessing database is pretty simple job using C# and ADO. In this sample code, I access an access database mcTest.mdb, which has a table called "Developer". I display contents of the table in a listbox. 

Just add a list box to the form and the following code to the form load. Don't forget to add reference to System.Data and System.Data.OleDb namespaces.

private void Form1_Load(object sender, System.EventArgs e)
{
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\mcTest.MDB";
string strSQL = "SELECT * FROM Developer" ;
// create Objects of ADOConnection and ADOCommand
OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbDataAdapter myCmd = new OleDbDataAdapter( strSQL, myConn );
myConn.Open();
DataSet dtSet = new DataSet();
myCmd.Fill( dtSet, "Developer" );
DataTable dTable = dtSet.Tables[0];
foreach( DataRow dtRow in dTable.Rows )
{
listBox1.Items.Add( dtRow["Name"].ToString());
listBox1.Items.Add( dtRow["Address"].ToString());
}
}

Login to add your contents and source code to this article
share this article :
post comment
 

is it possible connect to MS SQL Server from HTML Page using Javascript? Plz help me Thanks in advance

Posted by sailaja m Aug 16, 2011

Rashid,
Post your questions on the forums. Unfortunately I do not have free time to write products. I just write articles when I have free time from my work.

Good luck!

Posted by Mahesh Chand Nov 07, 2010

Hi Mahesh bhai,
I want to make web application to sent bulk email, id is in excel file.

Please help me,
you are the one can help.
Thanks,
Rashid
Ahmedabad(gujrat)
rashidchaki@gmail.com

Posted by Rashid Chaki Sep 18, 2010

Hi,
Lets say, the Access database that is used has a User & password property. How should I enter it?
Thanx. 

Posted by Dude Apr 28, 2010

I would love to see an updated publish of this article.

Posted by patrick Aug 01, 2009
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor