q: copy data from one data set to another

G

Guest

Hello,
I am trying to write the data I got from a web service to my table in SQL
Server
I need to append the dataset wsDS to the dataset ds and do update.

PVS.myWS.Loader load = new PVS.myWS.Loader();
DataSet wsDS=load.WsLoad();
dataGrid1.DataSource=wsDS;

string strConn = ConfigurationSettings.AppSettings["connectionString"];
SqlConnection sqlConn = new SqlConnection(strConn);

DataSet ds = new DataSet();
SqlDataAdapter daRS = new SqlDataAdapter("SELECT * From myTable", sqlConn);
SqlCommandBuilder cbRS = new SqlCommandBuilder(daRS);
sqlConn.Open();
daRS.Fill(ds,"myTable");

/* ??? here I need some code */
/* Append data in wsDS to ds to write it back to myTable */

daRS.Update(ds,"myTable");
sqlConn.Close();

Can anyone give me the easiest and fasted way?
 
K

Kevin Spencer

Well, you've got a couple of issues to deal with here, and a little clarity
about what is going on will help.

First, it is important to understand that a DataSet is a container for
DataTables, and usually contains schema information about the database that
contains the tables as well. The DataSet is *not* connected to the Database,
but contains a *copy* of what is in the database. It is populated by a
DataAdapter, which *does* connect to the database when necessary to update
either the DataSet contents from the database or vice versa.

So, first of all, we're not doing anything with the DataSet, just a
DataTable or DataTables *in* the DataSet. And the question I need to know
the answer to is, do you want to copy or move data in the database from one
table to another, or do you simply want to work with data from 2 different
data sources in the same DataTable?

If you want to copy or move data from one table in the database to another,
there's no reason to involve a DataSet or a DataAdapter. You simply call a
Stored Procedure or execute a query to do it. If you want to combine data
from 2 different data sources, you append rows to the DataTable in one
DataSet from the rows in a DataTable in the other, or from a query or Stored
Procedure.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
G

Guest

Hi Kevin,
Thank you very much for your reply.
Here is what I am trying to do:
1. Call web service and get data from a remote database (working see my
previous message for the code)
2. put data to a dataset (working)
3. show it in the data grid (working)
4. and put this data in my local database (how? I need to write this code)

How can I do this 4th step? Any idea and sample code will be appreciated.



Kevin Spencer said:
Well, you've got a couple of issues to deal with here, and a little clarity
about what is going on will help.

First, it is important to understand that a DataSet is a container for
DataTables, and usually contains schema information about the database that
contains the tables as well. The DataSet is *not* connected to the Database,
but contains a *copy* of what is in the database. It is populated by a
DataAdapter, which *does* connect to the database when necessary to update
either the DataSet contents from the database or vice versa.

So, first of all, we're not doing anything with the DataSet, just a
DataTable or DataTables *in* the DataSet. And the question I need to know
the answer to is, do you want to copy or move data in the database from one
table to another, or do you simply want to work with data from 2 different
data sources in the same DataTable?

If you want to copy or move data from one table in the database to another,
there's no reason to involve a DataSet or a DataAdapter. You simply call a
Stored Procedure or execute a query to do it. If you want to combine data
from 2 different data sources, you append rows to the DataTable in one
DataSet from the rows in a DataTable in the other, or from a query or Stored
Procedure.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

JIM.H. said:
Hello,
I am trying to write the data I got from a web service to my table in SQL
Server
I need to append the dataset wsDS to the dataset ds and do update.

PVS.myWS.Loader load = new PVS.myWS.Loader();
DataSet wsDS=load.WsLoad();
dataGrid1.DataSource=wsDS;

string strConn = ConfigurationSettings.AppSettings["connectionString"];
SqlConnection sqlConn = new SqlConnection(strConn);

DataSet ds = new DataSet();
SqlDataAdapter daRS = new SqlDataAdapter("SELECT * From myTable",
sqlConn);
SqlCommandBuilder cbRS = new SqlCommandBuilder(daRS);
sqlConn.Open();
daRS.Fill(ds,"myTable");

/* ??? here I need some code */
/* Append data in wsDS to ds to write it back to myTable */

daRS.Update(ds,"myTable");
sqlConn.Close();

Can anyone give me the easiest and fasted way?
 
K

Kevin Spencer

Hi Jim,

Okay, just a little more detail:
2. put data to a dataset (working)
3. show it in the data grid (working)
4. and put this data in my local database (how? I need to write this code)

You're putting data from a Web Service call into a DataSet. Then you're
displaying it in a DataGrid.

My oney question is, between #3 an #4, what is the connection? IOW, why
don't you just put it into your database, and then populate your DataSet
from your database? Is there some kind of time gap or other operation
between these 2 operations?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.


JIM.H. said:
Hi Kevin,
Thank you very much for your reply.
Here is what I am trying to do:
1. Call web service and get data from a remote database (working see my
previous message for the code)
2. put data to a dataset (working)
3. show it in the data grid (working)
4. and put this data in my local database (how? I need to write this code)

How can I do this 4th step? Any idea and sample code will be appreciated.



Kevin Spencer said:
Well, you've got a couple of issues to deal with here, and a little
clarity
about what is going on will help.

First, it is important to understand that a DataSet is a container for
DataTables, and usually contains schema information about the database
that
contains the tables as well. The DataSet is *not* connected to the
Database,
but contains a *copy* of what is in the database. It is populated by a
DataAdapter, which *does* connect to the database when necessary to
update
either the DataSet contents from the database or vice versa.

So, first of all, we're not doing anything with the DataSet, just a
DataTable or DataTables *in* the DataSet. And the question I need to know
the answer to is, do you want to copy or move data in the database from
one
table to another, or do you simply want to work with data from 2
different
data sources in the same DataTable?

If you want to copy or move data from one table in the database to
another,
there's no reason to involve a DataSet or a DataAdapter. You simply call
a
Stored Procedure or execute a query to do it. If you want to combine data
from 2 different data sources, you append rows to the DataTable in one
DataSet from the rows in a DataTable in the other, or from a query or
Stored
Procedure.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

JIM.H. said:
Hello,
I am trying to write the data I got from a web service to my table in
SQL
Server
I need to append the dataset wsDS to the dataset ds and do update.

PVS.myWS.Loader load = new PVS.myWS.Loader();
DataSet wsDS=load.WsLoad();
dataGrid1.DataSource=wsDS;

string strConn = ConfigurationSettings.AppSettings["connectionString"];
SqlConnection sqlConn = new SqlConnection(strConn);

DataSet ds = new DataSet();
SqlDataAdapter daRS = new SqlDataAdapter("SELECT * From myTable",
sqlConn);
SqlCommandBuilder cbRS = new SqlCommandBuilder(daRS);
sqlConn.Open();
daRS.Fill(ds,"myTable");

/* ??? here I need some code */
/* Append data in wsDS to ds to write it back to myTable */

daRS.Update(ds,"myTable");
sqlConn.Close();

Can anyone give me the easiest and fasted way?
 
G

Guest

Hi Kavin,
Ok thanks for the reply again. Here is the steps I was mentioning.
1. PVS.myWS.Loader load = new PVS.myWS.Loader();
2. DataSet wsDS=load.WsLoad();
3. dataGrid1.DataSource=wsDS;

This three steps show data in the grid in my application. Web service brings
this data from a remote database over internet which I do not have direct
connection.
Ok. If I can put the data into a table I can populate dataset from my
database. As you see web service returns a dataset. Can you tell me how can I
put the data directly into table and fill my dataset from there?
Thanks you very much for your help.



Kevin Spencer said:
Hi Jim,

Okay, just a little more detail:
2. put data to a dataset (working)
3. show it in the data grid (working)
4. and put this data in my local database (how? I need to write this code)

You're putting data from a Web Service call into a DataSet. Then you're
displaying it in a DataGrid.

My oney question is, between #3 an #4, what is the connection? IOW, why
don't you just put it into your database, and then populate your DataSet
from your database? Is there some kind of time gap or other operation
between these 2 operations?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.


JIM.H. said:
Hi Kevin,
Thank you very much for your reply.
Here is what I am trying to do:
1. Call web service and get data from a remote database (working see my
previous message for the code)
2. put data to a dataset (working)
3. show it in the data grid (working)
4. and put this data in my local database (how? I need to write this code)

How can I do this 4th step? Any idea and sample code will be appreciated.



Kevin Spencer said:
Well, you've got a couple of issues to deal with here, and a little
clarity
about what is going on will help.

First, it is important to understand that a DataSet is a container for
DataTables, and usually contains schema information about the database
that
contains the tables as well. The DataSet is *not* connected to the
Database,
but contains a *copy* of what is in the database. It is populated by a
DataAdapter, which *does* connect to the database when necessary to
update
either the DataSet contents from the database or vice versa.

So, first of all, we're not doing anything with the DataSet, just a
DataTable or DataTables *in* the DataSet. And the question I need to know
the answer to is, do you want to copy or move data in the database from
one
table to another, or do you simply want to work with data from 2
different
data sources in the same DataTable?

If you want to copy or move data from one table in the database to
another,
there's no reason to involve a DataSet or a DataAdapter. You simply call
a
Stored Procedure or execute a query to do it. If you want to combine data
from 2 different data sources, you append rows to the DataTable in one
DataSet from the rows in a DataTable in the other, or from a query or
Stored
Procedure.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

Hello,
I am trying to write the data I got from a web service to my table in
SQL
Server
I need to append the dataset wsDS to the dataset ds and do update.

PVS.myWS.Loader load = new PVS.myWS.Loader();
DataSet wsDS=load.WsLoad();
dataGrid1.DataSource=wsDS;

string strConn = ConfigurationSettings.AppSettings["connectionString"];
SqlConnection sqlConn = new SqlConnection(strConn);

DataSet ds = new DataSet();
SqlDataAdapter daRS = new SqlDataAdapter("SELECT * From myTable",
sqlConn);
SqlCommandBuilder cbRS = new SqlCommandBuilder(daRS);
sqlConn.Open();
daRS.Fill(ds,"myTable");

/* ??? here I need some code */
/* Append data in wsDS to ds to write it back to myTable */

daRS.Update(ds,"myTable");
sqlConn.Close();

Can anyone give me the easiest and fasted way?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top