Jump to content

Working with a Dataset


homiee

Recommended Posts

Hi everyone!I have this code:SqlConnection myConnection ...SqlDataAdapter myCommand ...DataSet ds = new DataSet(); myCommand.Fill(ds); Repeater1.DataSource = ds; Repeater1.DataBind();Assuming this code creates a table from the data collected from the SQL databases in Dataset "ds"so that will be ds.Tables[0]Table should look like this:ID | type | name | amount | date-------------------------------5 | 1 | homiee | 500 | 23/12/200710 | 0 | horsy | 208 | 10/20/2007my question is - is there any way to alter the data inside the table?let's say I want to change the data in the dataset (not in the database) - I want to change ALL types that equals to 1 to "YES" and all types that equals to 0 to "NO", what's the method?thanks!

Link to comment
Share on other sites

Thanks for the fast reply!But it seems there's an error:Input string was not in a correct format.Couldn't store <NO> in Type Column. Expected type is Int32.The "Type" column in Int32... but why should it matter as long as it's in a dataset?

Link to comment
Share on other sites

It matters because that is the datatype you setup and that is what it uses. I string is nto the same as an integer. The column doesn't knwo what to do with it. Post your sql statement I'll see if I can get it to cast the column as a different type before sending to the DataTable because once it is in the DataTable it is stuck as that datatype.

Link to comment
Share on other sites

SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * FROM BuyIDtable WHERE UID=\'" + UID + "\' ORDER BY BuyID DESC", myConnection);Maybe I can make a different dataset with a different repeater for the "Type" Column? -SqlDataAdapter myCommand = new SqlDataAdapter("SELECT Type FROM BuyIDtable WHERE UID=\'" + UID + "\' ORDER BY BuyID DESC", myConnection);<...><do whatever it needs to do in order to change Type 1 to Yes and Type 0 to No>myCommand.Fill(ds2);Repeater2.DataSource = ds2;Repeater2.DataBind();And then make Repeater2 show in Repeater1 where the type column is?Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...