"No i dont know how to fetch a row. please help."
OK - I've move over into the solution because this is going to need code, and it's easier to read here where I can format it correctly.
I'm not going to "give you the answer" - because there isn't "an answer", there are a huge range of possible answers, and I don't want to give you a solution that introduces things your tutor hasn't! Adding to your confusion doesn't help much... :laugh:
So, first thing to do is to find out what you do know:
1) Do you know what to do with an SqlCommand object?
2) An SqlAdapter?
3) An SqlDataReader?
3) A DataTable?
A quick look at the image you want to duplicate shows that it's probably a little advanced for your to actually look like that - it'd be quite a bit of work for
me - so we'll get something working and you can make it pretty later, OK?
Some other stuff I need to know: What system are you working for? website, WinForms, WPF?
It does make a difference!
"yeah! i know about those 4 things.
1. SqlCommand object,
2.SqlAdaptor
3) An SqlDataReader
4) A DataTable.
ok, lets start from base., not concentrating on graphics, jst fetching row i.e question and its options.
i am working on winForm."
OK - that helps a lot.
The simplest way to read data from the DB then:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT Question, op1, op2, op3, op4, [correct answer] FROM myTable WHERE Q_id=@ID", con))
{
cmd.Parameters.AddWithValue("@ID", questionIdValue);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
string question = (string) reader["Question"];
...
}
}
}
}
You can correct the column names and "fill in the blanks" for the rest of the row from that pretty easily.
(There are easier ways to read the data - a DataAdapter is less code - but then it gets more complex to use it as it is in a DataTable so this will do for the moment)
Then all you have to do is use the values:
labelForQuestion.Text = question;
checkBoxForOption1.Text = option1;
...
Make sense so far?