name randr

name randr

  • NA
  • 8
  • 0

Retrieving data from textbox

Dec 18 2008 1:18 AM

Hi all, I am having trouble retrieving data from a textbox. This is my code.

Dataset class:

public DataSet Ques() //create dataset for ListQue()

{

OleDbConnection cnn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Environment.CurrentDirectory.ToString() + "\\bin\\Debug\\database\\quiz.mdb");

cnn.Open();

string query = "SELECT ques,ans1,ans2,ans3,ans4 FROM questions";

OleDbCommand com = new OleDbCommand(query, cnn);

DataSet ds1 = new DataSet();

OleDbDataAdapter adpt = new OleDbDataAdapter(com);

adpt.Fill(ds1, "questions");

cnn.Close();

return ds1;

}

 

public class questions

{

public string answer1;

public string answer2;

public string answer3;

public string answer4;

}

 

ListQues() class:

 

private void ListQues()

{

DataSet ds1 = new DataSet();

ds1 = Ques();

for (int i = 0; i <= ds1.Tables["questions"].Rows.Count-1; i++)

{

questions q = new questions();

q.answer1 = ds1.Tables["questions"].Rows[i]["ans1"].ToString();

q.answer2 = ds1.Tables["questions"].Rows[i]["ans2"].ToString();

q.answer3 = ds1.Tables["questions"].Rows[i]["ans3"].ToString();

q.answer4 = ds1.Tables["questions"].Rows[i]["ans4"].ToString();

txtAns1.Text = q.ToString();

txtAns2.Text = q.ToString();

txtAns3.Text = q.ToString();

txtAns4.Text = q.ToString();

comboBox1.DataSource = ds1.Tables[0];

comboBox1.DisplayMember = "ques";

}

}

 

The thing is, it can get through the SQL statement and retrieve data from combobox but it doesn't show up in textboxes.

 

Any clues?


Answers (3)