0

hey i am trying to connect database table with my form in C#
Here is my code....

private void btn_quiz_Click(object sender, EventArgs e)
        {
            String constr = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\\Documents and Settings\\Zohaib\\My Documents\\Visual Studio 2010\\Projects\\CheckAbility\\Qusetions.accdb";
            OleDbConnection conn = new OleDbConnection(constr);
            conn.Open();
            OleDbCommand command = new OleDbCommand("SELECT * FROM Table1", conn);
            OleDbDataReader recordset = command.ExecuteReader();
            label3.Text = recordset[0].ToString();
        }

there is only one record in my table
but its giving me error

no data exist for the row column

Also tell me how to select one record from the table on the basis of id????
Plz rply soon
Thanx in Advance

Edited by __avd: Added [code]..[/code] tags.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by __avd
0

You need to invoke Read method.

OleDbDataReader recordset = command.ExecuteReader();
if(recordset.Read())
  label3.Text = recordset[0].ToString();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.