?
Solved

Write to an AccessData base

Posted on 2009-05-03
4
Medium Priority
?
201 Views
Last Modified: 2012-05-06
How is this done?

I have the following code that opens the database but how do I write to it?

The database Customer has three colums
name, phone, adress
con = new System.Data.OleDb.OleDbConnection();
        ds1 = new DataSet();
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= C:\\Documents and Settings\\MFL\\Dokumenter\\Visual Studio 2005\\WebSites\\WebSite\\WebSite\\Nwind.mdb";
        con.Open();
 
 
 
        con.Close();
        con.Dispose();
}

Open in new window

0
Comment
Question by:Mickeys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:cauos
ID: 24289134
this is an example how you can insert new row to access database
also check this link for more info:
http://msdn.microsoft.com/en-us/library/system.data.oledb(VS.71).aspx
public void InsertRow(string myConnectionString) 
{
   // If the connection string is null, use a default.
   if(myConnectionString == "") 
   {
      myConnectionString = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;" + 
      "Integrated Security=SSPI;";
   }
   OleDbConnection myConnection = new OleDbConnection(myConnectionString);
   string myInsertQuery = "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')";
   OleDbCommand myCommand = new OleDbCommand(myInsertQuery);
   myCommand.Connection = myConnection;
   myConnection.Open();
   myCommand.ExecuteNonQuery();
   myCommand.Connection.Close();
}

Open in new window

0
 

Author Comment

by:Mickeys
ID: 24289171
you say it should have a public void InsertRow(string myConnectionString)

what is myConnectonString?

I got this:
            private System.Data.OleDb.OleDbConnection con;
        private DataSet ds1;
        private System.Data.OleDb.OleDbDataAdapter da;
        con = new System.Data.OleDb.OleDbConnection();
        ds1 = new DataSet();
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= C:\\Documents and Settings\\MFL\\Dokumenter\\Visual Studio 2005\\WebSites\\WebSite\\WebSite\\Nwind.mdb";
        con.Open();
0
 
LVL 4

Accepted Solution

by:
cauos earned 2000 total points
ID: 24289238
this example for insert record into database;
the link above contains what you are looking for in details.
con = new System.Data.OleDb.OleDbConnection();
        ds1 = new DataSet();
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= C:\\Documents and Settings\\MFL\\Dokumenter\\Visual Studio 2005\\WebSites\\WebSite\\WebSite\\Nwind.mdb";
        con.Open();
 
  string myInsertQuery = "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')";
   OleDbCommand myCommand = new OleDbCommand(myInsertQuery);
   myCommand.Connection = myConnection;
   myConnection.Open();
   myCommand.ExecuteNonQuery();
   myCommand.Connection.Close();
 
 
        con.Close();
        con.Dispose();
}

Open in new window

0
 

Author Closing Comment

by:Mickeys
ID: 31577296
Great thx
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question