469,640 Members | 1,561 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,640 developers. It's quick & easy.

Assign values retrieved from a dataset to variables

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);

Nov 16 '05 #1
2 7081
"gjtired" <jo****@boystown.org> wrote in news:1108480381.259642.19910
@l41g2000cwc.googlegroups.com:
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/
Nov 16 '05 #2
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.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Chad Z. Hower aka Kudzu" <cp**@hower.org> wrote in message
news:Xn******************@127.0.0.1...
"gjtired" <jo****@boystown.org> wrote in news:1108480381.259642.19910
@l41g2000cwc.googlegroups.com:
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/


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jonas Hansson | last post: by
1 post views Thread by j.t.w | last post: by
2 posts views Thread by Andy B | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.