1

在登錄后的界面直接修改或刪除信息。
2
后臺(tái)數(shù)據(jù)庫表結(jié)構(gòu):
點(diǎn)擊刪除后,提醒確認(rèn)刪除,確認(rèn)后刪除信息
3
具體步驟:
1導(dǎo)入命名空間;
2 運(yùn)用Connection對(duì)象建立與數(shù)據(jù)庫連接;
3 打開連接;
4 利用Command對(duì)象的ExecuteReader()方法執(zhí)行Select查詢語句;
5 利用ExecuteReader()方法返回的DataReader對(duì)象讀取數(shù)據(jù),顯示到界面上;
6關(guān)閉連接。

4
界面從無供應(yīng)商到有供應(yīng)商
關(guān)鍵代碼:
5
DataGridView數(shù)據(jù)綁定流程:快速搭建商超管理系統(tǒng)數(shù)據(jù)庫SuperMarketSales:
方法:在數(shù)據(jù)庫服務(wù)器上,新建SuperMarketSales數(shù)據(jù)庫,并導(dǎo)入SuperMarketSales.sql腳本

在控件里找到DataSource,修改DataGridView的數(shù)據(jù)源。
6
重要代碼:查詢:
// 連接字符串,注意與實(shí)際環(huán)境保持一致
String connStr = ConfigurationManager.ConnectionStrings["SuperMarketSales"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(connStr);
try
{
// 連接數(shù)據(jù)庫
sqlConn.Open();
// DataGridView數(shù)據(jù)綁定
}
catch (Exception exp)
{
MessageBox.Show("訪問數(shù)據(jù)庫錯(cuò)誤:" + exp.Message);
}
finally
{
sqlConn.Close();
}
// 構(gòu)造命令
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();
// 自定義一個(gè)表(MyGoods)來標(biāo)識(shí)數(shù)據(jù)庫的GOODS表
adp.Fill(ds, "MyGoods");
// 指定DataGridView的數(shù)據(jù)源為DataSet的MyGoods表
this.dgv_Goods.DataSource = ds.Tables["MyGoods"];