I
izco
Hi all,
I'm trying to edit data in a dataset, and keep getting errors. I'm
selecting data from SQL, and a few different fields are either 1 or 0
based on the way questions were answered originally. I'm trying to
change the 1's to "Yes" the 0's to "No", but I'm having no luck.
Here's my code:
SqlDataAdapter myCommand = new SqlDataAdapter("SELECT firstName,
lastName, answer1, answer2, answer3 FROM myTable", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "List");
for (int i = 0; i < ds.Tables["List"].Rows.Count; i++)
{
if(ds.Tables["List"].Rows["answer1"].ToString() == "1"){
ds.Tables["List"].Rows["answer1"].ToString() = "Yes";
}
if(ds.Tables["List"].Rows["answer2"].ToString() == "1")
{
ds.Tables["List"].Rows["answer2"].ToString() = "Yes";
}
if(ds.Tables["List"].Rows["answer3"].ToString() == "1")
{
ds.Tables["List"].Rows["answer3"].ToString() = "Yes";
}
}
ResultsGrid.DataSource= ds.Tables["List"].DefaultView;
ResultsGrid.DataBind();
So, I get the data and dump it into a dataset. Then I go row by row
through the dataset looking for 1's, and attempt to change them. I can
change the 1's to 9's, so I'm on the right track (I think!) But, when
I try to change the 1's to "Yes" I get an "Input string was not in a
correct format" error, or a "the left-hand side of an assignment must
be a variable, property or indexer" error. What can I do to fix this?
There must be a way, right?
I'm kind of new at this and trying to add on to a previous developer's
code, so I can't change the current SQL table or muck with the data
that is in there. I just need it to display properly! Thanks for your
help!
Jim
I'm trying to edit data in a dataset, and keep getting errors. I'm
selecting data from SQL, and a few different fields are either 1 or 0
based on the way questions were answered originally. I'm trying to
change the 1's to "Yes" the 0's to "No", but I'm having no luck.
Here's my code:
SqlDataAdapter myCommand = new SqlDataAdapter("SELECT firstName,
lastName, answer1, answer2, answer3 FROM myTable", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "List");
for (int i = 0; i < ds.Tables["List"].Rows.Count; i++)
{
if(ds.Tables["List"].Rows["answer1"].ToString() == "1"){
ds.Tables["List"].Rows["answer1"].ToString() = "Yes";
}
if(ds.Tables["List"].Rows["answer2"].ToString() == "1")
{
ds.Tables["List"].Rows["answer2"].ToString() = "Yes";
}
if(ds.Tables["List"].Rows["answer3"].ToString() == "1")
{
ds.Tables["List"].Rows["answer3"].ToString() = "Yes";
}
}
ResultsGrid.DataSource= ds.Tables["List"].DefaultView;
ResultsGrid.DataBind();
So, I get the data and dump it into a dataset. Then I go row by row
through the dataset looking for 1's, and attempt to change them. I can
change the 1's to 9's, so I'm on the right track (I think!) But, when
I try to change the 1's to "Yes" I get an "Input string was not in a
correct format" error, or a "the left-hand side of an assignment must
be a variable, property or indexer" error. What can I do to fix this?
There must be a way, right?
I'm kind of new at this and trying to add on to a previous developer's
code, so I can't change the current SQL table or muck with the data
that is in there. I just need it to display properly! Thanks for your
help!
Jim