add rows to existing dataset

S

Steve

Is there a way to keep adding rows to an existing dataset? I have a stored
procedure that I need to call for every value, I then need to add the
results of the stored procedure to the same dataset or datatable so I can
validate it against my users.

so for example,
I need to call my stored procedure 3 times - once for each user

JSmith, SHenry, GDavid

I need to get the information for each user, collect it somehow, then pass
it all back to my validation method so I can make sure each user has the
correct information associated with it. Is there anyway of doing this?

I'm able to call the stored procedure 3 times by doing a foreach loop, but
its only returning me the data for the last user passed, I need all data for
all users.
 
N

Nicholas Paldino [.NET/C# MVP]

Steve,

Why not just call the Add method on DataRowCollection instance exposed
by the Rows property on the appropriate DataTable?
 
S

Steve

how does that work? I never used that.



Nicholas Paldino said:
Steve,

Why not just call the Add method on DataRowCollection instance exposed
by the Rows property on the appropriate DataTable?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Steve said:
Is there a way to keep adding rows to an existing dataset? I have a
stored procedure that I need to call for every value, I then need to add
the results of the stored procedure to the same dataset or datatable so I
can validate it against my users.

so for example,
I need to call my stored procedure 3 times - once for each user

JSmith, SHenry, GDavid

I need to get the information for each user, collect it somehow, then
pass it all back to my validation method so I can make sure each user has
the correct information associated with it. Is there anyway of doing
this?

I'm able to call the stored procedure 3 times by doing a foreach loop,
but its only returning me the data for the last user passed, I need all
data for all users.
 
N

Nicholas Paldino [.NET/C# MVP]

Steve,

You can create an array of objects which corresponds to the values in
the row you want to add (the order of the values has to correspond with the
order of the columns in the table), or create a new DataRow instance, set
the values on the instance and pass that to the Add method.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Steve said:
how does that work? I never used that.



Nicholas Paldino said:
Steve,

Why not just call the Add method on DataRowCollection instance exposed
by the Rows property on the appropriate DataTable?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Steve said:
Is there a way to keep adding rows to an existing dataset? I have a
stored procedure that I need to call for every value, I then need to add
the results of the stored procedure to the same dataset or datatable so
I can validate it against my users.

so for example,
I need to call my stored procedure 3 times - once for each user

JSmith, SHenry, GDavid

I need to get the information for each user, collect it somehow, then
pass it all back to my validation method so I can make sure each user
has the correct information associated with it. Is there anyway of doing
this?

I'm able to call the stored procedure 3 times by doing a foreach loop,
but its only returning me the data for the last user passed, I need all
data for all users.
 
S

Steve

I've done that actually in a foreach loop, but only the last person passed
is the only one showing data.


i have something like

string userList = txtUsername.txt;
string[] user= userList.split(',');

foreach(String u in users)
{
DataSet dsUsers = new DataSet();
dsUsers = GetUserDetails(u);
}

Public DataSet GetUserDetals(string userName)
{
DataSet ds = new DataSet();
ds = UserInformation.GetUserDetails(userName);
return ds;
}

and I only see the data for the last person pass.

i pass the users as
John, Greg, Dan, Kelly,

and so on so I want to see details for John, Greg, Dan and kelly and not
just for Kelly as I am now

Nicholas Paldino said:
Steve,

You can create an array of objects which corresponds to the values in
the row you want to add (the order of the values has to correspond with
the order of the columns in the table), or create a new DataRow instance,
set the values on the instance and pass that to the Add method.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Steve said:
how does that work? I never used that.



Nicholas Paldino said:
Steve,

Why not just call the Add method on DataRowCollection instance
exposed by the Rows property on the appropriate DataTable?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Is there a way to keep adding rows to an existing dataset? I have a
stored procedure that I need to call for every value, I then need to
add the results of the stored procedure to the same dataset or
datatable so I can validate it against my users.

so for example,
I need to call my stored procedure 3 times - once for each user

JSmith, SHenry, GDavid

I need to get the information for each user, collect it somehow, then
pass it all back to my validation method so I can make sure each user
has the correct information associated with it. Is there anyway of
doing this?

I'm able to call the stored procedure 3 times by doing a foreach loop,
but its only returning me the data for the last user passed, I need all
data for all users.
 
G

Guest

Steve,
Here is the pattern:

DataRow row=null;

foreach (string s in users )
{
row=MyDataTable.NewRow();
row["userName"]=s; // set any additional columns too
MyDataTable.Rows.Add(row);
}

-- Cheers,
Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com



Steve said:
I've done that actually in a foreach loop, but only the last person passed
is the only one showing data.


i have something like

string userList = txtUsername.txt;
string[] user= userList.split(',');

foreach(String u in users)
{
DataSet dsUsers = new DataSet();
dsUsers = GetUserDetails(u);
}

Public DataSet GetUserDetals(string userName)
{
DataSet ds = new DataSet();
ds = UserInformation.GetUserDetails(userName);
return ds;
}

and I only see the data for the last person pass.

i pass the users as
John, Greg, Dan, Kelly,

and so on so I want to see details for John, Greg, Dan and kelly and not
just for Kelly as I am now

Nicholas Paldino said:
Steve,

You can create an array of objects which corresponds to the values in
the row you want to add (the order of the values has to correspond with
the order of the columns in the table), or create a new DataRow instance,
set the values on the instance and pass that to the Add method.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Steve said:
how does that work? I never used that.



in message Steve,

Why not just call the Add method on DataRowCollection instance
exposed by the Rows property on the appropriate DataTable?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Is there a way to keep adding rows to an existing dataset? I have a
stored procedure that I need to call for every value, I then need to
add the results of the stored procedure to the same dataset or
datatable so I can validate it against my users.

so for example,
I need to call my stored procedure 3 times - once for each user

JSmith, SHenry, GDavid

I need to get the information for each user, collect it somehow, then
pass it all back to my validation method so I can make sure each user
has the correct information associated with it. Is there anyway of
doing this?

I'm able to call the stored procedure 3 times by doing a foreach loop,
but its only returning me the data for the last user passed, I need all
data for all users.
 
S

Steve

I've actually tried that and it failed as well.

I've been trying some different things and I am able to get everything back
for every user that I enter in the text and display them on seperate lines
so now I see

John|Smith|[email protected]
Kelly|Smith|[email protected]


but now when I try to parse out these strings I get nothing but
String.String[] and no values.
I have
String[] moreNames = username.tostring().split(','); //its all coming in
split by commas'
foreach(String n in moreName)
{
String[] u = n.toString().Split('|'); //split the | character
Response.write(u[0]) // I should see John and Kelly but instead Im'
seeing String.String[] on my page.
}


Peter Bromberg said:
Steve,
Here is the pattern:

DataRow row=null;

foreach (string s in users )
{
row=MyDataTable.NewRow();
row["userName"]=s; // set any additional columns too
MyDataTable.Rows.Add(row);
}

-- Cheers,
Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com



Steve said:
I've done that actually in a foreach loop, but only the last person
passed
is the only one showing data.


i have something like

string userList = txtUsername.txt;
string[] user= userList.split(',');

foreach(String u in users)
{
DataSet dsUsers = new DataSet();
dsUsers = GetUserDetails(u);
}

Public DataSet GetUserDetals(string userName)
{
DataSet ds = new DataSet();
ds = UserInformation.GetUserDetails(userName);
return ds;
}

and I only see the data for the last person pass.

i pass the users as
John, Greg, Dan, Kelly,

and so on so I want to see details for John, Greg, Dan and kelly and not
just for Kelly as I am now

in
message news:%23HRZkI%[email protected]...
Steve,

You can create an array of objects which corresponds to the values
in
the row you want to add (the order of the values has to correspond with
the order of the columns in the table), or create a new DataRow
instance,
set the values on the instance and pass that to the Add method.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

how does that work? I never used that.



"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in message Steve,

Why not just call the Add method on DataRowCollection instance
exposed by the Rows property on the appropriate DataTable?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Is there a way to keep adding rows to an existing dataset? I have a
stored procedure that I need to call for every value, I then need to
add the results of the stored procedure to the same dataset or
datatable so I can validate it against my users.

so for example,
I need to call my stored procedure 3 times - once for each user

JSmith, SHenry, GDavid

I need to get the information for each user, collect it somehow,
then
pass it all back to my validation method so I can make sure each
user
has the correct information associated with it. Is there anyway of
doing this?

I'm able to call the stored procedure 3 times by doing a foreach
loop,
but its only returning me the data for the last user passed, I need
all
data for all users.
 

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

Top