我正在尝试在Access数据库中获取用户的所有详细信息。但我似乎无法将每个列值保存到标签。这是我正在使用的代码。 UserId也已经为其分配了值
string connString = (@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=DataDirectory|HorseDB.mdb");
OleDbConnection conn = new OleDbConnection(connString);
conn.Open();
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
}
dbReader.Close();
conn.Close();