C#利用数据库相关知识点设计实现图书查询功能

img


请问各位老师如何实现这个功能😭

    private void 图书查询_Load(object sender, EventArgs e)
    {
        SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, "Select ClassName From tb_BookClass", null);
        while (dr.Read())
        {
            comboBox1.Items.Add(dr["ClassName"].ToString());
        }

        DataSet ds = SqlHelper.GetDataSet(CommandType.Text, "select * from tb_Book");
        dataGridView1.DataSource = ds.Tables[0];
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataSet ds = SqlHelper.GetDataSet(CommandType.Text, "select * from tb_Book where BookClass=@BookClass", new SqlParameter("@BookClass", comboBox1.Text));
        dataGridView1.DataSource = ds.Tables[0];
    }

using System.Data.SqlClient;
using System.Configuration;
combox控件右上角有个三角,通过链接可以显示数据库表的某列
private void button1_Click(object sender, EventArgs e)
{
string Connstr = ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString;//connstr是app.config里的连接数据库的语句
conn = new SqlConnection(Connstr);
sda = new SqlDataAdapter("select * from tb_Book where BookClass = '"+ comboBox1.Text +"'", conn);
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}

你老师姓孙对不对

这个就是下来框变动事件 在下拉框事件找到这个事件 SelectedIndexChanged 然后生成事件 在这个进行查询就可以了 sql是这么写的 select* from 图书表 where bookclass=‘“+this.下拉框名称.text+”’ 就可以了