ADD data to the Access database using ADO

Source: Internet
Author: User
Access|ado ADD data to the database using ADO

Tools used:visual C #. NET

This program shows how to insert data into an Access database using ADO and SQL query. I have an Access to database in Project\bin\debug directory. The My database name is Mctest.mdb. Can create your own database and copy in your project's debug directory. I am not attaching database and this code because of size problem.

I have a table ' Developer ' in this database which has four columns. I am inserting values into two columns Name and address in this code.

Using System;
Using System.Data;
Using System.Data.OleDb;
Namespace Adonetwritequery
{
<summary>
Summary description for Class1.
</summary>
Class Class1
{
static void Main (string[] args)
{
String strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\mctest.mdb ";
String strSQL = "INSERT into Developer (Name, address) VALUES (
' NewName ', ' newaddress ');

Create Objects of ADOConnection and Adocommand
OleDbConnection myconn = new OleDbConnection (STRDSN);
OleDbCommand mycmd = new OleDbCommand (strSQL, myconn);
Try
{
MyConn.Open ();
Mycmd.executenonquery ();
}
catch (Exception e)
{
Console.WriteLine ("Oooops.") I did it again:\n{0} ", E.message);
}
Finally
{
Myconn.close ();
}



}
}
}








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.