Datatable Update

M

mazda_88

Not sure where to post this, but this is the problem I am having. I
am trying to pass an id in a datatable that will be used to query the
database to extract the rest of the row. For example, suppose, I have
a customer id and this id is used to query the database to extract the
rest of the columns assoicated with the customer id. I update the
datatable column/row 0 associated with the customer id, and then call
a method with the datatable as an argument. This method then extracts
the customer_id from the datatable and then executes a stored
procedure that fills the data to the datatable. When this occurs
another row is added to the datatable with the results from the query.
Is there a way of doing this so that the results of the query update
row 0?

I know that there are a number of otherways of approaching the
problem, such as passing the customer_id instead of including the
value in the datatable. Or I could delete row 0 before executing the
stored procedure.

Thanks,
 
W

William Ryan eMVP

Hi Mazda:

On the one hand, it sounds like you may be making a few more trips to the db
than you want, and perhaps using two tables with a datarelation may be a
cleaner approach. However, to address your particulary problem. If you are
using the value of a column in the row to query the db, then you can overlay
the existing values with the values you get back. Let's say you have a
datarow with 4 columns, the first of which is customer_id 100. You hit the
db with your proc which corresponds to customer_id 100. You could iterate
through a datareader (or since you are using stored procs, I'd save the
overhead and use OutPut Parameters) and set dataTable.Rows[0]1], rows [0][2]
and Rows [0][3] to each respective valeu of the datareader or the output
params.

If I undestand your problem correctly, that should work but if I don't,
please let me know and I'll see what I can come up with.

Cheers,

Bill


www.devbuzz.com
www.knowdotnet.com
 

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