2.8

2.8

1.GIF效果图

2.8.gif

2.功能:

后台数据库表结构:


image.png

DataGridView数据绑定流程:


image.png

重要代码:
// 构造命令

String sqlStr = "select * from GOODS where 1=1 ";

// 添加查询条件
if (!this.tb_Id.Text.Trim().Equals("")){
sqlStr += " and ID='" + this.tb_Id.Text.Trim() + "'";
}

if (!this.tb_Name.Text.Trim().Equals("")){
sqlStr += " and NAME like '%" + this.tb_Name.Text.Trim() + "%'";
}

SqlCommand cmd = new SqlCommand(sqlStr, sqlConn);

// 将该查询过程绑定到DataAdapter
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd;

// 将DataSet和DataAdapter绑定
DataSet ds = new DataSet();
// 自定义一个表(MyGoods)来标识数据库的GOODS表
adp.Fill(ds, "MyGoods");

// 指定DataGridView的数据源为DataSet的MyGoods表
this.dgv_Goods.DataSource = ds.Tables["MyGoods"];

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容