473,473 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Updating DataSet

Greetings,

I have a dataSet where I return an ID, I now need to associate that ID
with the description, which is in another database. I think I am on
the right track, but am not sure:

DataSet myData = new DataSet();
myAdapter.Fill(myData);

foreach (DataRow dRow in myData.Tables[0].Rows)
{
int prodID = (int)dRow["prod_id"];

string sel = "SELECT prod_desc FROM product_master WHERE
prod_id = " + prodID;
SqlCommand cmd =
new SqlCommand(sel, new
SqlConnection(GetConnectionString(siteCode)));
cmd.Connection.Open();
SqlDataReader dr =
cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

}

return myData;

I am not sure how to update the dataSet???

Thanks in advance!

Jun 2 '06 #1
4 1300
http://msdn.microsoft.com/library/de...terdataset.asp

FYI.. Dataset can return multiple tables(with relation). Instead of
hitting the database in a loop, the foreign key relationship can be
processed in the code.

HTH,
Sam.

da******@gmail.com wrote:
Greetings,

I have a dataSet where I return an ID, I now need to associate that ID
with the description, which is in another database. I think I am on
the right track, but am not sure:

DataSet myData = new DataSet();
myAdapter.Fill(myData);

foreach (DataRow dRow in myData.Tables[0].Rows)
{
int prodID = (int)dRow["prod_id"];

string sel = "SELECT prod_desc FROM product_master WHERE
prod_id = " + prodID;
SqlCommand cmd =
new SqlCommand(sel, new
SqlConnection(GetConnectionString(siteCode)));
cmd.Connection.Open();
SqlDataReader dr =
cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

}

return myData;

I am not sure how to update the dataSet???

Thanks in advance!


Jun 2 '06 #2
Do you want to update the prod_desc? or the first dataset you get (about the
ID's),
If you want to modify the prod_desc, use a dataset instead of dataReader,
data Reader is read only.

To update the dataset, one ways is to go to the field, (like what you did in
the sameple "myData.Tables[0].Rows"), change the value and then call
ds.AcceptChanges() after you've made all the changes.

Gasnic
http://gasnicdev.blogspot.com/

<da******@gmail.com> wrote in message
news:11*********************@f6g2000cwb.googlegrou ps.com...
Greetings,

I have a dataSet where I return an ID, I now need to associate that ID
with the description, which is in another database. I think I am on
the right track, but am not sure:

DataSet myData = new DataSet();
myAdapter.Fill(myData);

foreach (DataRow dRow in myData.Tables[0].Rows)
{
int prodID = (int)dRow["prod_id"];

string sel = "SELECT prod_desc FROM product_master WHERE
prod_id = " + prodID;
SqlCommand cmd =
new SqlCommand(sel, new
SqlConnection(GetConnectionString(siteCode)));
cmd.Connection.Open();
SqlDataReader dr =
cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

}

return myData;

I am not sure how to update the dataSet???

Thanks in advance!

Jun 3 '06 #3
Hi,

I need to update the first DataSet, basically replace the ID with the
description from the other database.

I am not sure how you update or change a field in the dataSet, but I am
thankful for the advice. Guess I can research that aspect of it.

-Kevyn

Jun 4 '06 #4
I am actually very close now, as it does return the value I need, but
only for the first entry:

SqlConnection myConn = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["CRM_SystemConnection"].ConnectionString);
SqlDataAdapter myAdapter = new SqlDataAdapter(query, myConn);

DataSet myData = new DataSet();
myAdapter.Fill(myData);

DataColumn dc = new DataColumn();
myData.Tables[0].Columns.Add(dc);

foreach (DataRow dRow in myData.Tables[0].Rows)
{
int prodID = (int)dRow["prod_id"];

string sel = "SELECT prod_desc FROM product_master WHERE
prod_id = " + prodID;
SqlCommand cmd =
new SqlCommand(sel, new
SqlConnection(GetConnectionString(siteCode)));
cmd.Connection.Open();
SqlDataReader dr =
cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

while (dr.Read())
{
string someValue = dr["prod_desc"].ToString();

myData.Tables[0].Rows[0][dc] = someValue;

myData.AcceptChanges();
}
}

It only works for first row, and doesn't seem to want to work for
others in the dataSet. Any thoughts?

Jun 4 '06 #5

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

Similar topics

5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
2
by: susan.f.barrett | last post by:
Hi, Despite me being able to type the following in to SQL Server and it updating 1 row: > updatestockcategory 1093, 839 In my code, it is not updating any rows. dataSet = new DataSet();
0
by: OldStd | last post by:
Updating data using 2 data sets I am having some problems in updating the database using two datasets as suggested by someone. 1. Data is displayed in a data grid from a dataset generated using...
0
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,...
0
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...
0
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...
1
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...
0
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,...
1
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...
0
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...
0
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...
0
muto222
php
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.