Please help with Datasets.....

Hi all. I'm lost in the world of datasets.

I have filled a dataset (single table) from one database (Interbase using ODBC connection) and I now want to take that dataset and poplate an MSDE database table (using a sqlclient connection) with it.

How do I do it? All the documentation I can find refers to updating the data source the dataset was populated with, not updating a different database.

Please help,

Thanks in advance,
Kevin.

[448 byte] By [Elroacho] at [2007-12-16]
# 1
Your dataset probably has a related DataAdapter object. This class has 4 types of SqlCommands (Insert, Update, Delete, Select). Each SqlCommand has a Connection property.
This way you can define a differend database connection and query for each database action on that DataAdapter. So (after defining the right SqlCommands), running the .Select and .Insert method should do the job.
cspare at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 2
This could work :D

Just one more question. What is the best way to reference the data in the dataset for the insert sql command? Is there a way to do it in one go or will I have to create a loop to step through the dataset?

Cheers,
kevin.

Elroacho at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 3
you need to call the Update method and pass the DataSet to update its content in the new database. The Insert Command's SQL should be written to insert a single row. The Update method automatically loops over the rows of the dataset and inserts them into the database.

Regards,
Saurabh Nandu
www.MasterCSharp.com
www.AksTech.com

SaurabhNandu at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 4
Cheers for the advice, however I can't get it to work. The target database is set up as an SQLConnection. I'm trying to set up an adapter for it but I'm not having any joy.

I gather once I have this done I can use the dataset I populated by doing an ODBCAdapter.fill(dataset) from my source OdbcConnection and do a MSDEAdapter.Update(dataset) to my MSDEConnection.

any tips or am I doing this totally wrong.

Cheers,
Kevin.

Elroacho at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 5
Kevin,

I've not done what you are trying to do there, but it seems to me that you will need to be using the same connection type for both databases. Since you don't appear to have a provider for the source DB other than ODBC, then I would try connecting to the destination DB with ODBC. You can use an ODBC connection on MS SQL Server. It just won't be as efficient as an SQL Server connection.

HTH

OtisMukinfus at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 6
Cheers, I'll give it a go tonight.

Kevin.

Elroacho at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...