Reading multiple records from a database
-
i wanna pull multiple records in from a database and display them in different labels I was thinking of returning them in an array then adding them to the specified labels, can anyone point me to the an example or aid me. sample code
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=BABOO;uid=sa;password=sa;database=quiz");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
string query;
query = "select QuestionText,AnswerA,AnswerB,AnswerC,AnswerD from quest where QuestionID='1'";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
nt rbCount = Convert.ToInt32(TextBox2.Text);
//iin textbox enter how many record want to display
RadioButton[] radioButtons = new RadioButton[rbCount];
for (int i = 0; i < rbCount; ++i)
{
radioButtons[i] = new RadioButton();radioButtons[i].Text = dr.GetValue(1).ToString();
}Please i need your help
Ferron
-
i wanna pull multiple records in from a database and display them in different labels I was thinking of returning them in an array then adding them to the specified labels, can anyone point me to the an example or aid me. sample code
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=BABOO;uid=sa;password=sa;database=quiz");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
string query;
query = "select QuestionText,AnswerA,AnswerB,AnswerC,AnswerD from quest where QuestionID='1'";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
nt rbCount = Convert.ToInt32(TextBox2.Text);
//iin textbox enter how many record want to display
RadioButton[] radioButtons = new RadioButton[rbCount];
for (int i = 0; i < rbCount; ++i)
{
radioButtons[i] = new RadioButton();radioButtons[i].Text = dr.GetValue(1).ToString();
}Please i need your help
Ferron
So, this seems a little retarded to me. 1 - you want to have a textbox showing how many answers to show ? So, what if the right answer gets hidden ? 2 - how do you make sure that textbox2 contains a number ? 3 - why don't your variables have real names ? 4 - You're reading the same value from the answer list every time 5 - you never add the radio buttons to your UI
Christian Graus Driven to the arms of OSX by Vista.
-
So, this seems a little retarded to me. 1 - you want to have a textbox showing how many answers to show ? So, what if the right answer gets hidden ? 2 - how do you make sure that textbox2 contains a number ? 3 - why don't your variables have real names ? 4 - You're reading the same value from the answer list every time 5 - you never add the radio buttons to your UI
Christian Graus Driven to the arms of OSX by Vista.
i know, that's why i need your help to sort it out the write way. basically what i have is 3 textbox text[1] text[2] text[3] if three records are in the database it should bring back three sets of record all in their respective textbox. Plz can u help
Ferron
-
i know, that's why i need your help to sort it out the write way. basically what i have is 3 textbox text[1] text[2] text[3] if three records are in the database it should bring back three sets of record all in their respective textbox. Plz can u help
Ferron
So the possible answers go in textboxes, not in radio buttons ? Are you saying the number of answers is flexible ? I would do this with a data bound control, assuming I had to show more than one question on a page.
Christian Graus Driven to the arms of OSX by Vista.
-
So the possible answers go in textboxes, not in radio buttons ? Are you saying the number of answers is flexible ? I would do this with a data bound control, assuming I had to show more than one question on a page.
Christian Graus Driven to the arms of OSX by Vista.
Yes I want to show the results in the text box? I have it created in a form. Is the the data bound control flexible? Can the realit be formatted in a form like manner, for say a application form?
Ferron
-
Yes I want to show the results in the text box? I have it created in a form. Is the the data bound control flexible? Can the realit be formatted in a form like manner, for say a application form?
Ferron
Yeah, you can define a template for a data bound control and show the data any way you like.
Christian Graus Driven to the arms of OSX by Vista.
-
Yeah, you can define a template for a data bound control and show the data any way you like.
Christian Graus Driven to the arms of OSX by Vista.
I have used a form view, its working well, the thing is how do I get it to display records one under the other instead of paging?
Ferron
-
Yeah, you can define a template for a data bound control and show the data any way you like.
Christian Graus Driven to the arms of OSX by Vista.
I used a data list control to display all my records, but i have been trying to add paging capability. :(
Ferron