473,835 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

q: copy data from one data set to another

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.WsLoa d();
dataGrid1.DataS ource=wsDS;

string strConn = ConfigurationSe ttings.AppSetti ngs["connectionStri ng"];
SqlConnection sqlConn = new SqlConnection(s trConn);

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

/* ??? 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
4 2491
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**@discussio ns.microsoft.co m> wrote in message
news:7E******** *************** ***********@mic rosoft.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.WsLoa d();
dataGrid1.DataS ource=wsDS;

string strConn = ConfigurationSe ttings.AppSetti ngs["connectionStri ng"];
SqlConnection sqlConn = new SqlConnection(s trConn);

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

/* ??? 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
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**@discussio ns.microsoft.co m> wrote in message
news:7E******** *************** ***********@mic rosoft.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.WsLoa d();
dataGrid1.DataS ource=wsDS;

string strConn = ConfigurationSe ttings.AppSetti ngs["connectionStri ng"];
SqlConnection sqlConn = new SqlConnection(s trConn);

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

/* ??? 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
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**@discussio ns.microsoft.co m> wrote in message
news:12******** *************** ***********@mic rosoft.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**@discussio ns.microsoft.co m> wrote in message
news:7E******** *************** ***********@mic rosoft.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.WsLoa d();
> dataGrid1.DataS ource=wsDS;
>
> string strConn = ConfigurationSe ttings.AppSetti ngs["connectionStri ng"];
> SqlConnection sqlConn = new SqlConnection(s trConn);
>
> DataSet ds = new DataSet();
> SqlDataAdapter daRS = new SqlDataAdapter( "SELECT * From myTable",
> sqlConn);
> SqlCommandBuild er cbRS = new SqlCommandBuild er(daRS);
> sqlConn.Open();
> daRS.Fill(ds,"m yTable");
>
> /* ??? 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
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.WsLoa d();
3. dataGrid1.DataS ource=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**@discussio ns.microsoft.co m> wrote in message
news:12******** *************** ***********@mic rosoft.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**@discussio ns.microsoft.co m> wrote in message
news:7E******** *************** ***********@mic rosoft.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.WsLoa d();
> dataGrid1.DataS ource=wsDS;
>
> string strConn = ConfigurationSe ttings.AppSetti ngs["connectionStri ng"];
> SqlConnection sqlConn = new SqlConnection(s trConn);
>
> DataSet ds = new DataSet();
> SqlDataAdapter daRS = new SqlDataAdapter( "SELECT * From myTable",
> sqlConn);
> SqlCommandBuild er cbRS = new SqlCommandBuild er(daRS);
> sqlConn.Open();
> daRS.Fill(ds,"m yTable");
>
> /* ??? 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
5818
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same kind. It sounds simple but evidently .NET has difficulty with this concept for some reason. I do understand that .NET objects are created on the GC heap but that doesn't mean that they couldn't be copied from another object of the same kind when...
4
2256
by: xuatla | last post by:
Hi, How to copy a pointer to another pointer? Can I do in the following way: // START double *copyfrom = new double; double *copyto = new double;
4
4806
by: Yudan Yi | last post by:
I have a problem to copy (assign) a matrix to another matrix. Curreny, I know copy the number using loops, while it will take some time, I wonder if there have faster method. The following code explain my situation detailed. double ** matrixa, **matrixb; int nrow = 10, mcol = 10; matrixa = initmatrix(nrow, mcol); // allocate memory a matrixb = initmatrix(nrow, mcol); // allocate memory b // copy a => b for (int i=0;i<nrow;i++)
8
2941
by: luis molina Micasoft | last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make 40 threads of file.copy , 40 copys of files at same time the system is going down and stop responding, this is when i'm working with cifs (shares). there is another solution to copy files than file.copy in .net?
7
11649
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
5
2930
by: Clodoaldo Pinto Neto | last post by:
Hello, How to make sure COPY TO writes the table lines to the file in the same order they were inserted? I'm producing html pages in pl/pgsql and using COPY TO to write then to file. Occasionaly, about once in 7 or 9, the lines are copied to the file out of the order they were inserted in the table. The lines have one only column of the type text.
13
2485
by: Jeroen | last post by:
Hi all, I'm trying to implement a certain class but I have problems regarding the copy ctor. I'll try to explain this as good as possible and show what I tried thusfar. Because it's not about a certain code syntax but more a 'code architecture' thing , I'll use simple example classes (which are certainly not complete or working...) just to illustrate the idea (and I may make some mistakes because I'm not that experienced...). The...
3
12866
by: maheshkadam | last post by:
Hi friends I am new to perl so please guide me. I have one application which created backup log file every day.But it appends that file so you can see logs for different day in one file only. My requirement is to copy backup log for the specific day (yesterday) and write in other file. That file will be mailed to admin for ready reference. So here is some text from that log file
0
3223
by: Taxman | last post by:
Windows XP, MS Office Excel 2003 If the tasks, I’m trying accomplish have been addressed previously (separately or in combination). Please, provide the links or keyword search to find them. I’ve been searching for code for each part of the task separately and trying to piece together multiple macros, that do something similar, to what I’m trying to accomplish in my over all task, but I’m not having a lot of luck. So, here’s the entire task,...
0
9653
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
10815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10562
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
10236
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
9348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5639
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4434
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
2
3997
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.