PC Review


Reply
Thread Tools Rate Thread

ADO.NET - Adding Records to a database

 
 
Darryn Ross
Guest
Posts: n/a
 
      18th Jul 2003
Hi,

I am trying to insert and update records into a database if have created in
access. I am unsure of the most efficient way of doing this, and have been
trying to work it our for ages.

Here is what i have so far, any help would be appreciated.

OleDbConnection DtlsConnection = new OleDbConnection() ;
OleDbCommand DtlsCommand = new OleDbCommand() ;
OleDbDataAdapter DtlsAdapter = new OleDbDataAdapter() ;
DataSet DtlsDs = new DataSet() ;

DtlsConnection.ConnectionString = StrConnectionPath ;
DtlsConnection.Open() ;

DtlsCommand.CommandText = "Select * From tbl" ;
DtlsCommand.Connection = SecurityDtlsConnection ;

DtlsAdapter.SelectCommand = DtlsCommand ;
DtlsAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey ;
DtlsAdapter.Fill(DtlsDs, "tbl") ;

I need to add a record to the database table "tbl" which has two fields
'Code' and 'Name'. 'Code' is a unique number (primary key) with a length of
7 and 'Name' is text with a Length of 50.

Is this the code that i need to implement to add a new record?....

DataRow tblRow ;
tblRow = DtlsDs.Tables["tbl"].NewRow() ;
tblRow["Code"] = 1234567 ;
tblRow["Name"] = "Test Name" ;
DtlsDs.Tables["tbl"].Rows.Add(tblRow) ;

How do i update an existing record in the database?... is this the way...

DataRow tblRow ;
tblRow = SecurityDtlsDs.Tables["tbl"].Rows.Find(1234567) ;
tblRow["Name"] = "New Name" ;
SecurityDtlsDs.Tables["tbl"].AcceptChanges() ;

Any help would be appreciated.

Kind Regards
Darryn Ross


 
Reply With Quote
 
 
 
 
Jerry
Guest
Posts: n/a
 
      18th Jul 2003
Darryn,
It generally looks right, but where does the dataset DtlsDs become
SecurityDtlsDs ?

"Darryn Ross" <(E-Mail Removed)> wrote in message
news:e#(E-Mail Removed)...
> Hi,
>
> I am trying to insert and update records into a database if have created

in
> access. I am unsure of the most efficient way of doing this, and have been
> trying to work it our for ages.
>
> Here is what i have so far, any help would be appreciated.
>
> OleDbConnection DtlsConnection = new OleDbConnection() ;
> OleDbCommand DtlsCommand = new OleDbCommand() ;
> OleDbDataAdapter DtlsAdapter = new OleDbDataAdapter() ;
> DataSet DtlsDs = new DataSet() ;
>
> DtlsConnection.ConnectionString = StrConnectionPath ;
> DtlsConnection.Open() ;
>
> DtlsCommand.CommandText = "Select * From tbl" ;
> DtlsCommand.Connection = SecurityDtlsConnection ;
>
> DtlsAdapter.SelectCommand = DtlsCommand ;
> DtlsAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey ;
> DtlsAdapter.Fill(DtlsDs, "tbl") ;
>
> I need to add a record to the database table "tbl" which has two fields
> 'Code' and 'Name'. 'Code' is a unique number (primary key) with a length

of
> 7 and 'Name' is text with a Length of 50.
>
> Is this the code that i need to implement to add a new record?....
>
> DataRow tblRow ;
> tblRow = DtlsDs.Tables["tbl"].NewRow() ;
> tblRow["Code"] = 1234567 ;
> tblRow["Name"] = "Test Name" ;
> DtlsDs.Tables["tbl"].Rows.Add(tblRow) ;
>
> How do i update an existing record in the database?... is this the way...
>
> DataRow tblRow ;
> tblRow = SecurityDtlsDs.Tables["tbl"].Rows.Find(1234567) ;
> tblRow["Name"] = "New Name" ;
> SecurityDtlsDs.Tables["tbl"].AcceptChanges() ;
>
> Any help would be appreciated.
>
> Kind Regards
> Darryn Ross
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help adding database records =?Utf-8?B?QmlnU2Ft?= Microsoft VB .NET 8 9th Aug 2007 03:37 PM
Database design and adding new records =?Utf-8?B?RGF2ZQ==?= Microsoft Access Database Table Design 1 18th Nov 2006 09:42 AM
Adding only new records from another database =?Utf-8?B?TmlyIE4=?= Microsoft Access Getting Started 4 20th Aug 2006 04:50 PM
Re: Database-programming adding records Bob Microsoft Frontpage 1 15th Jan 2005 08:46 PM
Re: Adding New Records To Excel Database.. steve Microsoft Excel Programming 0 18th Aug 2003 09:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:30 AM.