所以我想从列表框中读取所选项目,从数据库中读取SELECT,其中id = value from listbox并显示完整详细信息到消息框...但是我发现它我得到错误就可以有人请帮助我该怎么解决这个......
代码
public List<Students> FullDetails(Students student)
{
List<Students> studentList = new List<Students>();
try
{
command.CommandText = "SELECT FROM Students WHERE ID = " + student.Id;
command.CommandType = CommandType.Text;
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Students s = new Students();
s.Id = Convert.ToInt32(reader["ID"].ToString());
s.Name = reader["Name"].ToString();
s.LName = reader["LName"].ToString();
s.FName = reader["FName"].ToString();
s.MName = reader["MName"].ToString();
s.Absences = reader["Absences"].ToString();
s.Degrees = reader["Degrees"].ToString();
studentList.Add(s);
}
return studentList;
}
catch (Exception)
{
throw;
}
finally
{
if (connection != null)
{
connection.Close();
}
}
}
表格代码
Students s = new Students();
s = search_ls.SelectedItem as Students;
string fd = conn.FullDetails(s).ToString();
MessageBox.Show(fd);
答案 0 :(得分:3)
您似乎错过了选择查询中的字段列表。我想你的意思是SELECT和FROM之间的星号:
SELECT * FROM Students WHERE ID = ...