我无法弄清楚是什么错误。我想从数据库表中检索一条记录并将它们发送出去。我的表中有 9 个字段。第二个字段的数据是搜索词。同一数据可以有多个记录。如果有很多,那么它必须一次显示每条记录。怎么可能编码呢?
我将 C#.Net 用于逻辑,将 Ms Access 用于后端(数据库)
这是我的代码:
string[] arr = new string[9];
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="C:\PassWordSaver\Passwords.mdb;Persist Security Info=True;");
con.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM pwd Where Title = '"+textBox2+"'", con);
OleDbDataReader reader = cmd.ExecuteReader();
reader.Read();
//while (reader.Read())
//{
for (int i = 0; i < 9; i++)
{
arr[i] = reader.GetValue(i).ToString();
MessageBox.Show("The New data is " + arr[i] + ".", "Created", MessageBoxButtons.OK);
}
//}
reader.Close();
MessageBox.Show("Data Added Successfully. " + arr[2] + " is the user name.", "Created", MessageBoxButtons.OK);