By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,563 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,563 IT Pros & Developers. It's quick & easy.

q: copy data from one data set to another

P: n/a
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?

May 16 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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." <JI**@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
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?

May 16 '06 #2

P: n/a
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" wrote:
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." <JI**@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
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?


May 16 '06 #3

P: n/a
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." <JI**@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com... 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" wrote:
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." <JI**@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
> 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?
>


May 16 '06 #4

P: n/a
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" wrote:
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." <JI**@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
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" wrote:
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." <JI**@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
> 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?
>


May 16 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.