Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# with Access DAtabases?

C# with Access DAtabases?

Scheduled Pinned Locked Moved C#
csharptutorialquestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Azel Low
    wrote on last edited by
    #1

    I am trying to grasp how to use select, update, insert and delete command. I tried reading from some books Programming C# by Oreilly but it just doesnt really explain it in detail. I was hoping if anyone can point me to some article (don't seem to have them at code project) where i can learn how to perform the above operations on MS ACCESS databases. thanks

    M 1 Reply Last reply
    0
    • A Azel Low

      I am trying to grasp how to use select, update, insert and delete command. I tried reading from some books Programming C# by Oreilly but it just doesnt really explain it in detail. I was hoping if anyone can point me to some article (don't seem to have them at code project) where i can learn how to perform the above operations on MS ACCESS databases. thanks

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      Look at OleDbConnection or OdbcConnection (Framework 1.1, some people have indicated that ODBC seems to perform better than OLE DB when invoked from C#). Simple example:

      using ( OleDbConnection conn = new OleDbConnection() )
      {
      conn.ConnectionString =
      @"Provider=Microsoft.Jet.OLEDB.4.0;" +
      @"User ID=Admin;" +
      @"Data Source=FPNWIND.MDB;" +
      @"Mode=Read|Share Deny Read|Share Deny Write";

      using ( OleDbCommand cmd = new OleDbCommand() )
      {
      cmd.CommandText =
      "SELECT CategoryName FROM Categories ORDER BY CategoryID";
      cmd.Connection = conn;

        conn.Open();
      
        OleDbDataReader rdr = cmd.ExecuteReader();
      
        try
        {
           while ( rdr.Read() )
           {
              System.Console.WriteLine( 
                 "Category: {0}",
                 rdr.GetString( 0 ) );
           }
        }
        finally
        {
           rdr.Close();
        }
      

      }
      }

      To try this, create a new C# console application, paste into Main and add using System.Data; using System.Data.OleDb; at the top. This code opens the FPNWIND.MDB database (supplied with Office 2000) and outputs a list of all known categories to the console. For simple manipulations of data, use OleDbCommand's Execute_Xxx_ functions. If you don't expect any results (for example, if you're running an INSERT, UPDATE or DELETE statement), use ExecuteNonQuery. If you only want a single data value (the first column of the first row of the results), use ExecuteScalar. If you have an OleDbDataReader open on a connection, you can only scroll forwards through the data, and you cannot modify the data. You cannot do anything else with that connection until you have either read all the data (Read returns false) or have closed the reader. ADO.NET does not have an equivalent of classic ADO's live update of recordsets. The closest is essentially a batch mode involving a DataSet (an offline cache of one or more DataTables) and an OleDbDataAdapter. DataSet and DataTable are general classes; you use a DataAdapter from the appropriate provider to fill the data set or table and reflect any modifications back to the data source.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups