modify data in dataset

modularbeing

Well-known member
Joined
Jan 8, 2004
Messages
63
Im not too familiar with datasets other than just doing a fill and binding it to something. But for the project im currently working on I think I need to directly modify the data in the dataset unless anyone has a better process.

I am filling a dataset and binding it to a datagrid. The data containts a field that holds a foreign key that relates to another value in the database. I need to replace the integer value and replace it with the actual string value. I could easily use a sqldatareader and modify the value as it loops through the records but Im not sure how I can create a dataset from a sqldatareader.

thanks
Josh
 
You wouldnt create a dataset using a datareader, fill your dataset using a dataadapter then bind the dataset to your datagrid, modify the data using the datagrid and then call the dataadapters update method to update the data back to the underlying source.

Although, if your updating a foreign key you may get stuck when it comes to referential integrity between the two tables.
 
stustarz said:
You wouldnt create a dataset using a datareader, fill your dataset using a dataadapter then bind the dataset to your datagrid, modify the data using the datagrid and then call the dataadapters update method to update the data back to the underlying source.

Although, if your updating a foreign key you may get stuck when it comes to referential integrity between the two tables.


I need to update the data before i bind it to the datagrid for display because for instance I have a column fkAction which will display as 1 or 2 in the datagrid and means nothing to the people viewing it so I need to replace that 1 or 2 with Buy or Sell
 
well i imagine fkaction contains the key to your foreign table, this foreign table will contain the descriptive value buy or sell. So select the descriptive value from your lookup table using a join on the related fields, do this in your actual Select statement to populate your dataset.

If you need more on this let me know
 
stustarz said:
well i imagine fkaction contains the key to your foreign table, this foreign table will contain the descriptive value buy or sell. So select the descriptive value from your lookup table using a join on the related fields, do this in your actual Select statement to populate your dataset.

If you need more on this let me know

yah, thats what I wanted to do but the database guy doesnt want to because this proc is used elsewhere, etc. I dont understand why he cant just add return an extra column with the string value. Because if I have to do it in code to modify it that just means extra connections to the database, more resources etc.
 
Well, if i understand this correctly, your creating a databound datagrid on a page, so you would be coding a datacommand, adapter and dataset etc.. cant you just set the datacommand to commandtype.text and code the select statement?, this wouldnt interfere with other procedures because the command will only be used for this dataset on this datagrid.

Im under the impression your pulling the records using a stored procedure (using SQL server??), so dont use that and type the select statement instead....

If you really want to you could then use the datareader object to bind to the datagrid but then you still need to set a select statement or stored procedure to populate the dr, so either way its the SQL that should be changed to pull in the descriptive value. Saying that you could populate your datareader and loop through and add each row to the datagrid modifying the integer to the text you require as you do this- but this is a very long way around the situation, you need to manually create your columns, and enter each value to each column etc...
 
One of our policies is to always use stored procedures so I cant do sql in code. I guess ill just have to keep bugging the DB guy to change it or do it the long way. Thanks
 
Back
Top