从id = value的数据库中读取ListBox SelectedItem和SELECT

本文关键字:ListBox 读取 SelectedItem SELECT 数据库 id value | 更新日期: 2023-09-27 17:50:48

所以我想从列表框中读取选定的项目,并从数据库中SELECT,其中id = value从列表框中显示完整的详细信息到消息框…但我找不到它,我得到错误扔能有人帮我如何解决这个问题…

代码
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);

从id = value的数据库中读取ListBox SelectedItem和SELECT

您似乎错过了选择查询中的字段列表。我想你是指SELECT和FROM之间的星号:

SELECT * FROM Students WHERE ID = ...