473,597 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataSet in new table of a Access database

Hi all !
I have datas in a dataset. I would like to save them in a new table
(just created). Do I have to run trought all recordsets with an Insert
into statement ? (it takes very long)

Thanks
Dec 31 '05 #1
8 1991
Marcel,

You can just create a OleDbDataAdapte r with the insert statement
attached to the InsertCommand property. Then, you can just pass the data
set in and it should update the table.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Marcel Hug" <ma**********@c h.abb.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi all !
I have datas in a dataset. I would like to save them in a new table (just
created). Do I have to run trought all recordsets with an Insert into
statement ? (it takes very long)

Thanks

Dec 31 '05 #2
Hi Nicholas
You can just create a OleDbDataAdapte r with the insert statement
attached to the InsertCommand property. Then, you can just pass the data
set in and it should update the table.


I tried this, but it does not work....! :-((((

public void CreateNewBackup (DataSet backupDataSet, BackupTable backupTable)
{
try
{
string strNewBackupTab le = this.CreateNewB ackupTable(back upTable);

if(this.dbConne ction.State == ConnectionState .Closed)
{
this.dbConnecti on.Open();
}

OleDbCommand dbCommand = new OleDbCommand("I NSERT INTO " +
strNewBackupTab le + " (Entry, DateMain, Issued, LastUpdt, Modified,
Version, VersionText, VSTATUS) VALUES(?, ?, ?, ?, ?, ?, ?, ?)",
this.dbConnecti on);
dbCommand.Param eters.Add("Entr y", "ENTRY");
dbCommand.Param eters.Add("Date Main", "DATEMAIN") ;
dbCommand.Param eters.Add("Issu ed", "Issued");
dbCommand.Param eters.Add("Last Updt", "LASTUPDT") ;
dbCommand.Param eters.Add("Modi fied", "Modified") ;
dbCommand.Param eters.Add("Vers ion", "VERSION");
dbCommand.Param eters.Add("Vers ionText", "VersionTex t");
dbCommand.Param eters.Add("VSTA TUS", "VSTATUS");

this.dbAdapter. InsertCommand = dbCommand;
this.dbAdapter. TableMappings.A dd(strNewBackup Table,
backupDataSet.T ables[0].TableName);
this.dbAdapter. Fill(backupData Set);
}
finally
{
this.dbConnecti on.Close();
}
}
Dec 31 '05 #3
Marcel,

You have to be a little more specific when you say it doesn't work.
What exactly happens?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Marcel Hug" <ma**********@c h.abb.com> wrote in message
news:Od******** ******@TK2MSFTN GP09.phx.gbl...
Hi Nicholas
You can just create a OleDbDataAdapte r with the insert statement
attached to the InsertCommand property. Then, you can just pass the data
set in and it should update the table.


I tried this, but it does not work....! :-((((

public void CreateNewBackup (DataSet backupDataSet, BackupTable
backupTable)
{
try
{
string strNewBackupTab le = this.CreateNewB ackupTable(back upTable);

if(this.dbConne ction.State == ConnectionState .Closed)
{
this.dbConnecti on.Open();
}

OleDbCommand dbCommand = new OleDbCommand("I NSERT INTO " +
strNewBackupTab le + " (Entry, DateMain, Issued, LastUpdt, Modified,
Version, VersionText, VSTATUS) VALUES(?, ?, ?, ?, ?, ?, ?, ?)",
this.dbConnecti on);
dbCommand.Param eters.Add("Entr y", "ENTRY");
dbCommand.Param eters.Add("Date Main", "DATEMAIN") ;
dbCommand.Param eters.Add("Issu ed", "Issued");
dbCommand.Param eters.Add("Last Updt", "LASTUPDT") ;
dbCommand.Param eters.Add("Modi fied", "Modified") ;
dbCommand.Param eters.Add("Vers ion", "VERSION");
dbCommand.Param eters.Add("Vers ionText", "VersionTex t");
dbCommand.Param eters.Add("VSTA TUS", "VSTATUS");

this.dbAdapter. InsertCommand = dbCommand;
this.dbAdapter. TableMappings.A dd(strNewBackup Table,
backupDataSet.T ables[0].TableName);
this.dbAdapter. Fill(backupData Set);
}
finally
{
this.dbConnecti on.Close();
}
}

Dec 31 '05 #4
Nicholas
You have to be a little more specific when you say it doesn't work.
What exactly happens?


Hmm is a little bit difficult. After creating the new table exists. Then
i try to insert the datas of the dataset into the new table. in the
datatable of the dataset are more columns then in the new table. This i
would like to fit by the InsertCommand.
After the Update (or fill) command, the new table is still empty. No
exception or something.
That's why i think it is difficult...

Thanks and a happy new year
Dec 31 '05 #5
Marcel,

How are you getting the rows into the dataset in the first place? You
have to add them manually so that the data adapter sees that they have been
added.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Marcel Hug" <ma**********@c h.abb.com> wrote in message
news:uN******** ******@TK2MSFTN GP12.phx.gbl...
Nicholas
You have to be a little more specific when you say it doesn't work.
What exactly happens?


Hmm is a little bit difficult. After creating the new table exists. Then i
try to insert the datas of the dataset into the new table. in the
datatable of the dataset are more columns then in the new table. This i
would like to fit by the InsertCommand.
After the Update (or fill) command, the new table is still empty. No
exception or something.
That's why i think it is difficult...

Thanks and a happy new year

Dec 31 '05 #6
Nicholas,
How are you getting the rows into the dataset in the first place? You
have to add them manually so that the data adapter sees that they have been
added.


I have to databases (DB1 and DB2). The DB2 is my "backup" DB. I get the
datas from The DB1 with a OleDBDataAdapte r to the Dataset and would like
to write some of them into the DB2 with an other OleDBAdapter.

What do you mean with "add manually" ? Is my solution not running ? What
do you suggest a best solution ?

Thanks + Happy New Year
Jan 1 '06 #7
Marcel,

Each data row in the dataset has a state associated (is it added,
edited, deleted, etc, etc). The data adapter looks at this state to
determine if it should update the row when cycling through the rows.

When you initially select the rows from the table, the status is
considered unchanged. If you pass this back to the adapter without doing
anything to it, it doesn't know the rows should be added.

In .NET 2.0, you can cycle through the rows in your data table, and call
the SetAdded method on them to set the flag for the state to added.

In .NET 1.1 and before, what you will have to do is create a copy of the
data table (an empty one), and manually add the rows to the new data table,
so that the added flag is set, and then pass that data table to the data
adatper (or the data set with the new data table).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Marcel Hug" <ma**********@c h.abb.com> wrote in message
news:eE******** ******@tk2msftn gp13.phx.gbl...
Nicholas,
How are you getting the rows into the dataset in the first place?
You have to add them manually so that the data adapter sees that they
have been added.


I have to databases (DB1 and DB2). The DB2 is my "backup" DB. I get the
datas from The DB1 with a OleDBDataAdapte r to the Dataset and would like
to write some of them into the DB2 with an other OleDBAdapter.

What do you mean with "add manually" ? Is my solution not running ? What
do you suggest a best solution ?

Thanks + Happy New Year

Jan 1 '06 #8
Nicholas,

At frist lot of thanks for your help. Now it works ! :-)))
I have solved my problem like this.
First I have done a Select-Command of the new backup-table, to get a
empty datatable with the right schema.

then i went through my datas in the dataset and added them into the
created datatable.

After this i created a OleDbCommandBui lder to create the insert command
and then i updated the database with the datatable and this insert command.

This works fine and fast.

But now I have a little question.
Before I used the command builder, I wrote the SQL-Statement manually.
But with the manually created oledbcommand it was not working. also if I
took the same sql-statement.
But i can not explain why ????

Thanks
Regards

Marcel
Each data row in the dataset has a state associated (is it added,
edited, deleted, etc, etc). The data adapter looks at this state to
determine if it should update the row when cycling through the rows.

When you initially select the rows from the table, the status is
considered unchanged. If you pass this back to the adapter without doing
anything to it, it doesn't know the rows should be added.

In .NET 2.0, you can cycle through the rows in your data table, and call
the SetAdded method on them to set the flag for the state to added.

In .NET 1.1 and before, what you will have to do is create a copy of the
data table (an empty one), and manually add the rows to the new data table,
so that the added flag is set, and then pass that data table to the data
adatper (or the data set with the new data table).

Jan 1 '06 #9

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

Similar topics

3
378
by: Simon Harvey | last post by:
Hi everyone, I was wondering if it is possible, to use SQL to return more than one table at a time into a dataset. I only know the basics of SQL and so I'm not sure if I'm just asking a stupid question. But, I'm not proud! :-) I'm using Ado.net and I'm wanting to load a DataSet object with several independent tables. (For those who arent ADO.net programmers, a DataSet can hold multiple tables and the relationships and contraints...
0
1779
by: Neo | last post by:
I was wondering what is the "right" way to deal with datasets is. Particularly sharing DataSets between forms. Here is my situation. I have a simple Customer Database, that holds some information about Customers including thier address. Lets call this Table "Customers". The Customers Table references another Table for Address information, for instance I have a table of "Zipcodes", Now I want an app with two forms, one form to browse my...
1
6662
by: Jeroen Pot | last post by:
Hi, I have a dataset "Mydataset" which contains of a few fields. (lets say dept_id and dept_name) A user can select several of these, and i want to export this to an access database. I have a database with one table (dept) and identical colums as the dataset. But i can't figure out how to get the dataset into the database.
1
16577
by: Arpan | last post by:
The following ASPX code snippet creates a DataSet programmatically right from the scratch: 'create an empty DataSet Dim objDS As New DataSet("MyDataSet") 'create a new table & add columns Dim dTable As New DataTable("Users") dTable.Columns.Add("ID",System.Type.GetType("System.Int32")) dTable.Columns.Add("FirstName",System.Type.GetType("System.String")) dTable.Columns.Add("LastName",System.Type.GetType("System.String"))
0
5805
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database which indexes computer magazine articles for personal reference. I am developing a Visual Basic.NET program whose sole purpose is to enter new records into the database. No updates to existing entries, no deletions, and no display
22
4215
by: EMW | last post by:
Hi, I managed to create a SQL server database and a table in it. The table is empty and that brings me to my next chalenge: How can I get the info in the table in the dataset to go in an empty SQL table? Is there a short way like the FILL method to get data into the dataset or do I have to read each datarow in the table and write it one at the time to the
13
1820
by: Lars Netzel | last post by:
hi! myDataSet that is fillled from an Access 2000 db and includes ONE table From that Table in myDataSet I create myDataView and use a Rowfilter to get a few rows that i work with (i need a DataView cause I do a lot of filtering) The problem is the primary key field (a unique counter), let's call it "TBL_ID".
14
2114
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
2
3693
by: Carl Summers | last post by:
I have a table in an Access database that has no sort applied in Access. When I fill a dataset with data from that table (the entire one dimensional table) my dataset is sorted differently than the database. This would not be a problem, and really isn't a problem except that it means I have to search the dataset each time I want to find a particular record instead of just storing a variable. Which brings me to a different question....
3
3058
by: don | last post by:
I have written a program to hold a sales contact db. It is written in c# express. an update is sent from head office in xl format, i need to import only the new rows to an access database. I have gotten this far: a separate OleDbconnection to each source, which reads the entire data source (select *) into the same dataset, but different tables.
0
7967
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
7885
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
8381
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...
1
8031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
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
5428
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
3923
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2403
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.