473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do I add a record to an MS Access database

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
Nov 17 '05 #1
1 2686
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" <ro***@videotron.ca> wrote in message
news:Aw*********************@weber.videotron.net.. .
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

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for...
6
by: DebbieG | last post by:
I have created a database for a client and was told that it was to be a one-user database. Well, you know the next statement ... now they want 3 people to be able to use the database. (FYI, I...
5
by: Steve Strik | last post by:
My Problem: I have created a database here at work that is exhibiting some very strange behaviour. Essentially the database is structured in a manner where one table is a master record table...
1
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database...
10
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be...
0
by: Cindy Huyser | last post by:
I have an Access 2000 database behind a threaded Java application that that can have have concurrent access to the same table (but not the same record). The database is set up for shared access...
4
by: corey11 | last post by:
I'm a very low-level developer with limited VB knowledge but nonetheless was able to put together a very user-friendly and extremely helpful Access 97 database for my company some 10 years back. We...
25
by: tekctrl | last post by:
Anyone: I have a simple MSAccess DB which was created from an old ASCII flatfile. It works fine except for something that just started happening. I'll enter info in a record, save the record,...
12
by: tekctrl | last post by:
Environment; Win2K PC with 1Gb of RAM and plenty of HD space running Access 2002 Issue; Access presents a blank data entry form in the Forms view when the New Record icon is used. However, it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.