Take the 2-minute tour ×

I am trying to get all the details of a User in an Access database. But i cant seem to save each columns value to a label. Here is the code i am using. Also UserId has a value assigned to it already

  string connString = (@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=DataDirectory|HorseDB.mdb");
  OleDbConnection conn = new OleDbConnection(connString);
  OleDbCommand cmd = conn.CreateCommand();
  cmd.CommandText = @"SELECT * FROM [Users] WHERE [UserId] = @UserId ";
  cmd.Parameters.AddWithValue("@UserId", UserId);
  OleDbDataReader dbReader = cmd.ExecuteReader();
  while (dbReader.Read())
      accountUserIdLabel.Text = dbReader.GetValue(0).ToString();
      //Will add other labels once this works
share|improve this question
What problem do you have? Any error? No records returned? –  Claudio Redi Jul 8 '13 at 12:21
That looks like it should work. In what way does it not? –  David Jul 8 '13 at 12:22
the label doesn't have the value after it runs –  Cheesy Jul 8 '13 at 12:24
Are you referencing to the right column? try to eliminate asterisk (*) and write the specific column name like "SELECT Id FROM Users" –  rajeem_cariazo Jul 8 '13 at 12:25
@Cheesy: When you debug this, what value do you get from dbReader.GetValue()? What other values are available? –  David Jul 8 '13 at 12:25
show 5 more comments

Your Answer



Browse other questions tagged or ask your own question.