Assign values retrieved from a dataset to variables

  • Thread starter Thread starter gjtired
  • Start date Start date
G

gjtired

Currently I am retrieving values from a dataset and assigning the
values to a textbox. I then assign the value from the textbox to a
variable. I don't need the values in the textbox at all. I'm sure there
is an easier way than I'm doing it. Any suggestions or help would be
appreciated. Below is a snippet of code to show what I'm currently
doing.

string cmdQuestionEdit="SELECT Question_Subject, "+
"Question_Weight, "+
"QuestionType_ID, " +
"Question_Status, "+
"Question_QuestionContent, "+
"Quiz_ID, " +
"SortType_ID, "+
"Quiz_Version, " +
"Quiz_Number, " +
"Question_Version, " +
"Question_Number, " +
"QuestionType_ID " +
"FROM Question " +
"Where '"+txtQuestionID.Text+"' = " +
"Question_ID and '"+txtQuizID.Text+"' " +
"= Quiz_ID ";

sqlConnection1.Open();
SqlDataAdapter daEdit=new SqlDataAdapter(cmdQuestionEdit,
sqlConnection1);
daEdit.Fill(dsMain1,"Question");
DataTable dtEdit = dsMain1.Tables["Question"];

foreach (DataRow questionRow in dtEdit.Rows)
{
txtVersion.Text = questionRow["Question_Version"].ToString
().Trim();
txtNumber.Text = questionRow["Question_Number"].ToString
().Trim();

}//end for

//Edit quiz
//get values fom drop down list
valEditQuizVersion = int.Parse(txtVersion.Text);
valEditQuizNumber = int.Parse(txtNumber.Text);
 
gjtired said:
Currently I am retrieving values from a dataset and assigning the
values to a textbox. I then assign the value from the textbox to a
variable. I don't need the values in the textbox at all. I'm sure there
is an easier way than I'm doing it. Any suggestions or help would be
appreciated. Below is a snippet of code to show what I'm currently
doing.

What is the question? How to do it without the text boxes? To me the questino
is why are you not just reading directly from the datatable?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
 
I'd also add that the original poster can use typed datasets to gain more
'syntactic sugar' and make the code reading the dataset more readable and
intuitive.
 
Back
Top