一.效果圖

QQ圖片20181202130454.gif
二.主要功能
1.在窗口加載出來時顯示商品信息:通過SELECT語句進行查詢
2.通過點擊修改和刪除可以執(zhí)行相應的操作:通過INSERT和SELECT語句進行修改和刪除
三.ADO.NET刪除數(shù)據庫的流程
獲取所要修改關聯(lián)對象的主鍵
string goodsId = this.dgv_Goods["Id", e.RowIndex].Value.ToString();連接字符串
String connStr = ConfigurationManager.ConnectionStrings["SuperMarketSales"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(connStr);
3.連接數(shù)據庫
sqlConn.Open();
4.構造刪除命令
String sqlStr = "delete from GOODS where ID=@id";
SqlCommand cmd = new SqlCommand(sqlStr, sqlConn);
5.SQL字符串參數(shù)賦值
cmd.Parameters.Add(new SqlParameter("@id", goodsId));
- 將命令發(fā)送給數(shù)據庫
int res = cmd.ExecuteNonQuery();
7.根據返回值判斷是否修改成功
四.迭代過程
在原來的商品錄入界面添加一個供應商及ComboBox控件
編寫代碼讓ComboBox的數(shù)據源為DataSet的MySupplier表

image.png
五.DataGridView數(shù)據綁定流程

。.gif
六.貼入代碼并描述
1.窗口加載出來時顯示商品信息

image.png
效果圖:

image.png
3.修改和刪除商品信息

image.png