473,699 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2701
Here is my code, btw:

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

// OleDbSample.cs

// compile with: /r:system.dll /r:system.data.d ll /r:system.xml.dl l

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

// csc /r:system.dll /r:system.data.d ll /r:system.xml.dl l oledbsample.cs

using System;

using System.Data;

using System.Data.Ole Db;

using System.Xml.Seri alization;

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 USINGPROJECTSYS TEM

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

#else

string strAccessConn = "Provider=Micro soft.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.Table s.Add("Categori es");
// Create Access objects:

OleDbConnection myAccessConn = new OleDbConnection (strAccessConn) ;

OleDbCommand myAccessCommand = new
OleDbCommand(st rAccessSelect,m yAccessConn);

OleDbDataAdapte r myDataAdapter = new OleDbDataAdapte r(myAccessComma nd);

myAccessConn.Op en();

try

{

myDataAdapter.F ill(myDataSet," Categories");

}

finally

{

myAccessConn.Cl ose();

}

try

{

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

// into an array:

DataTableCollec tion dta = myDataSet.Table s;

foreach (DataTable dt in dta)

{

Console.WriteLi ne("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.WriteLi ne("{0} tables in data set", myDataSet.Table s.Count);

Console.WriteLi ne("{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.WriteLi ne("{0} rows in Categories table",
myDataSet.Table s["Categories "].Rows.Count);

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

// we can read it here:

Console.WriteLi ne("{0} columns in Categories table",
myDataSet.Table s["Categories "].Columns.Count) ;

DataColumnColle ction drc = myDataSet.Table s["Categories "].Columns;

int i = 0;

foreach (DataColumn dc in drc)

{

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

// data type:

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

}

DataRowCollecti on dra = myDataSet.Table s["Categories "].Rows;

foreach (DataRow dr in dra)

{

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

Console.WriteLi ne("CategoryNam e[{0}] is {1}", dr[0], dr[1]);

}

}

catch (Exception e)

{

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

}

}

}

"Roy Gourgi" <ro***@videotro n.ca> wrote in message
news:Aw******** *************@w eber.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
3743
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 Office 2000. I am creating a database to track student athletes. I have created the following tables. The table title is to the far left, with fields under each. The common field will be the StudentID field, which is their student number assigned...
6
5670
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 have never created a database for multiusers. I've done some searching but not finding what I want.) I have split the database. In Tools, Options, I have set the following: Default open mode = Shared Default record locking = Edited Record
5
2222
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 (tbl_MainRegister) providing a unique identifier for documents and a means for identifying the docuement type. There are then 4 additional tables (tbl_Meetings, tbl_Documents, tbl_Project, tbl_Correspondence) which store the document details.
1
5416
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 database so I could sort the records by the date at which they were entered. Well now I've deleted some of those records so its of course causing gaps in the records. The record number in Access no longer matches my record number that I...
12
20921
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 contains the paths to the pictures. The database consists of two tables: TABLE DATA ID Name LastName
10
12705
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 certain that MyVar will be set to the key-field value that was created when the Append query ran. Now, there are other ways to do it - I know - that will ensure you 'nab' the correct record. But I was wondering
0
4098
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 with "No locks" as the default, so that optimistic record locking should take place, and "Open databases using record-level locking" is selected. Each Java thread gets a new connection to the database, then updates its record. One of my users has...
4
2392
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 use the database for inventory, job costing, employee records, timecard recording, nearly everything except the hard core accounting. The database is shared by 20 users over a network. Every 3 or 4 years I archive and purge the data to keep the...
25
20555
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, and try to move to another record and get an Access error "Record is too large". The record is only half filled, with many empty fields. If I remove the added data or delete some older data, then it saves ok and works fine again. Whenever I'm...
12
3277
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 won't allow any fields to have data entered into them. I can edit & save existing records without problem. When I go into the Tables view, I can add records and data ok and save without problem. I go back into the Table and I can see the data. ...
0
8615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9173
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9033
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7748
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6533
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5872
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.