homiee Posted April 17, 2007 Share Posted April 17, 2007 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 More sharing options...
aspnetguy Posted April 17, 2007 Share Posted April 17, 2007 for(int i=0;i<ds.Tables[0].Rows.Count;i++){ if(ds.Tables[0].Rows[i]["type"] == "1") ds.Tables[0].Rows[i]["type"] = "YES"; else ds.Tables[0].Rows[i]["type"] = "NO";} Link to comment Share on other sites More sharing options...
homiee Posted April 17, 2007 Author Share Posted April 17, 2007 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 More sharing options...
aspnetguy Posted April 17, 2007 Share Posted April 17, 2007 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 More sharing options...
homiee Posted April 17, 2007 Author Share Posted April 17, 2007 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 More sharing options...
aspnetguy Posted April 17, 2007 Share Posted April 17, 2007 give me a minute first. it is a lot less work to change the datatype in the sql then to setup and fill custom DataTables. Link to comment Share on other sites More sharing options...
aspnetguy Posted April 17, 2007 Share Posted April 17, 2007 try this sql SELECT UID,CAST(type AS VARCHAR(3)) AS type,name,amount,date FROM BuyIDtable WHERE UID=\'" + UID + "\' ORDER BY BuyID DESC Link to comment Share on other sites More sharing options...
homiee Posted April 17, 2007 Author Share Posted April 17, 2007 Thanks alot! it works great! Link to comment Share on other sites More sharing options...
aspnetguy Posted April 17, 2007 Share Posted April 17, 2007 glad to help. good luck with the rest of your project Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now