Solved

Write to an AccessData base

Posted on 2009-05-03
4
192 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
  • 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 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now