Re: How do I add a record to an MS Access database

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Here is my code, btw:

//Copyright (C) 2000 Microsoft Corporation. All rights reserved.

// OleDbSample.cs

// compile with: /r:system.dll /r:system.data.dll /r:system.xml.dll

// To build this sample from the command line, use the command:

// csc /r:system.dll /r:system.data.dll /r:system.xml.dll oledbsample.cs

using System;

using System.Data;

using System.Data.OleDb;

using System.Xml.Serialization;

public class MainClass {

public static void Main ()

{

// Set Access connection and select strings.

// The path to BugTypes.MDB must be changed if you build the sample

// from the command line:

#if USINGPROJECTSYSTEM

string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=..\\..\\BugTypes.MDB";

#else

string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=BugTypes.MDB";

#endif

string strAccessSelect = "SELECT * FROM Categories";

// Create the dataset and add the Categories table to it:

DataSet myDataSet = new DataSet();

myDataSet.Tables.Add("Categories");


// Create Access objects:

OleDbConnection myAccessConn = new OleDbConnection(strAccessConn);

OleDbCommand myAccessCommand = new
OleDbCommand(strAccessSelect,myAccessConn);

OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);

myAccessConn.Open();

try

{

myDataAdapter.Fill(myDataSet,"Categories");

}

finally

{

myAccessConn.Close();

}

try

{

// A dataset can contain multiple tables, so let's get them all

// into an array:

DataTableCollection dta = myDataSet.Tables;

foreach (DataTable dt in dta)

{

Console.WriteLine("Found data table {0}", dt.TableName);

}


// The next two lines show two different ways you can get the

// count of tables in a dataset:

Console.WriteLine("{0} tables in data set", myDataSet.Tables.Count);

Console.WriteLine("{0} tables in data set", dta.Count);

// The next several lines show how to get information on a

// specific table by name from the dataset:

Console.WriteLine("{0} rows in Categories table",
myDataSet.Tables["Categories"].Rows.Count);

// The column info is automatically fetched from the database, so

// we can read it here:

Console.WriteLine("{0} columns in Categories table",
myDataSet.Tables["Categories"].Columns.Count);

DataColumnCollection drc = myDataSet.Tables["Categories"].Columns;

int i = 0;

foreach (DataColumn dc in drc)

{

// Print the column subscript, then the column's name and its

// data type:

Console.WriteLine("Column name[{0}] is {1}, of type {2}",i++ ,
dc.ColumnName, dc.DataType);

}

DataRowCollection dra = myDataSet.Tables["Categories"].Rows;

foreach (DataRow dr in dra)

{

// Print the CategoryID as a subscript, then the CategoryName:

Console.WriteLine("CategoryName[{0}] is {1}", dr[0], dr[1]);

}

}

catch (Exception e)

{

Console.WriteLine("Oooops. Caught an exception:\n{0}", e.Message);

}

}

}

"Roy Gourgi" <royng@xxxxxxxxxxxx> wrote in message
news:AwR7f.39358$bh4.1772451@xxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> I am using VS.NET 2003 and I have made a connection to a MS Access
> database using the Server Explorer. Is this connection permanent, meaning
> that it will be there every time I reopen my program. Furthermore, how do
> I add, delete, find, update a record?
>
> TIA
> Roy
>
>


.



Relevant Pages

  • Re: CreateTimerQueueTimer fails unexpectedly
    ... so you are multiplexing communication with several devices over a single TCP connection as well as having multiple TCP connections to various controllers. ... When sending this is easy since you can build a whole command and send it in a single write, but on read you must buffer the read results and parse out the responses. ...
    (microsoft.public.win32.programmer.kernel)
  • RE: Dialin problem
    ... # /etc/ppp/ppp.conf File for dial out modem to ISP and Dial in modem ... # connection to this FBSD system. ... # it's default options profile set to, NO command echo ATE0 and NO ... Edit /etc/ttys to enable a getty on the port where the dialin ...
    (freebsd-questions)
  • Re: VFP Updates?
    ... Try talking ODBC or OleDb and they say HU. ... make up my apps so that what ever they want to run has to be from a command ... kind of connection and assign it the right to do exactly what you want. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: [SLE] Setting up DSL on SUSE 10.1
    ... I won't faint at command line. ... SUSE or Mepis and the non computer oriented PCLinuxOS. ... In some OS's such as MS's the network will be confiured and on. ... on the DSL connection? ...
    (SuSE)
  • Re: More ASP.Net Newbie Questions
    ... The Command is then what you're doing with this connection, ... In regards to your final point, making grids and controls in general do ... > Connection and Recordset objects into, like, 37 different things. ...
    (microsoft.public.dotnet.framework.aspnet)