Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
GeneralRe: LOWORD and HIBYTE Pin
Andrew day14-Oct-03 4:31
Andrew day14-Oct-03 4:31 
GeneralReading Remote Registry using C# Pin
winterminute10-Oct-03 5:49
winterminute10-Oct-03 5:49 
GeneralPost processing paint on user controls Pin
Tomaž Štih10-Oct-03 5:01
Tomaž Štih10-Oct-03 5:01 
GeneralEnums - Creating at runtime Pin
Andrew day10-Oct-03 2:46
Andrew day10-Oct-03 2:46 
GeneralRe: Enums - Creating at runtime Pin
James Simpson10-Oct-03 6:21
James Simpson10-Oct-03 6:21 
GeneralRe: Enums - Creating at runtime Pin
Andrew day10-Oct-03 8:48
Andrew day10-Oct-03 8:48 
QuestionC# with Access DAtabases? Pin
Azel Low10-Oct-03 1:18
Azel Low10-Oct-03 1:18 
AnswerRe: C# with Access DAtabases? Pin
Mike Dimmick10-Oct-03 2:31
Mike Dimmick10-Oct-03 2:31 
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 ExecuteXxx 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.
GeneralWindows Hooks Pin
vikramlinux10-Oct-03 0:15
vikramlinux10-Oct-03 0:15 
GeneralRe: Windows Hooks Pin
Nick Parker10-Oct-03 2:22
protectorNick Parker10-Oct-03 2:22 
QuestionControlPaint class and Windows XP Themes? Pin
Chris Richner9-Oct-03 23:24
Chris Richner9-Oct-03 23:24 
AnswerRe: ControlPaint class and Windows XP Themes? Pin
J. Dunlap10-Oct-03 9:12
J. Dunlap10-Oct-03 9:12 
AnswerRe: ControlPaint class and Windows XP Themes? Pin
Joe Woodbury13-Oct-03 12:45
professionalJoe Woodbury13-Oct-03 12:45 
GeneralRe: ControlPaint class and Windows XP Themes? Pin
Chris Richner14-Oct-03 10:45
Chris Richner14-Oct-03 10:45 
GeneralMinimize to system tray Pin
devvvy9-Oct-03 22:05
devvvy9-Oct-03 22:05 
GeneralRe: Minimize to system tray Pin
Anonymous9-Oct-03 23:09
Anonymous9-Oct-03 23:09 
GeneralRe: Minimize to system tray Pin
devvvy10-Oct-03 7:24
devvvy10-Oct-03 7:24 
GeneralRe: Minimize to system tray Pin
Guillermo Rivero10-Oct-03 7:32
Guillermo Rivero10-Oct-03 7:32 
GeneralRe: Minimize to system tray Pin
devvvy10-Oct-03 7:34
devvvy10-Oct-03 7:34 
GeneralI got it, but Title didn't get repainted properly. Pin
devvvy10-Oct-03 7:48
devvvy10-Oct-03 7:48 
GeneralRe: I got it, but Title didn't get repainted properly. Pin
Guillermo Rivero10-Oct-03 7:53
Guillermo Rivero10-Oct-03 7:53 
GeneralRe: I got it, but Title didn't get repainted properly. Pin
devvvy10-Oct-03 8:12
devvvy10-Oct-03 8:12 
GeneralRe: Minimize to system tray Pin
JJF00711-Oct-03 4:48
JJF00711-Oct-03 4:48 
GeneralRe: Minimize to system tray Pin
devvvy11-Oct-03 4:51
devvvy11-Oct-03 4:51 
Generaladding data to event Pin
gonenb9-Oct-03 21:33
gonenb9-Oct-03 21:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.