刚入手Oracle,存储过程和sqlserver的区别好大啊,折腾了半天也不清楚,发帖得当好多好心人大师们的帮助,实在感激啊
为了给刚入门的好朋友们一点小小的指引,现把我折腾成功的关于“添加、修改、删除”的示例show一下,
[color=#FF0000]目前还缺少列表GetList()、展示GetModel()以及验证Exists()的,欢迎大师们提供[/color]!
web层:
- C# code
//添加 //数据填充 SystemCodeModel SystemCodeModel = new SystemCodeModel(); SystemCodeModel.CodeLb = this.txtCodeLb.Text; SystemCodeModel.LbName = this.txtLbName.Text; SystemCodeModel.CodeValue = this.txtCodeValue.Text; SystemCodeModel.CodeName = this.txtCodeName.Text; //调用BLL层Add SystemCodeBLL.Add(SystemCodeModel);//修改: //数据填充 SystemCodeModel SystemCodeModel = new SystemCodeModel(); SystemCodeModel.CodeLb = this.txtCodeLb.Text; SystemCodeModel.LbName = this.txtLbName.Text; SystemCodeModel.CodeValue = this.txtCodeValue.Text; SystemCodeModel.CodeName = this.txtCodeName.Text; //调用BLL层Update SystemCodeBLL.Update(SystemCodeModel);
//删除:
- C# code
//删除事件 protected void GVList_RowDeleting(object sender, GridViewDeleteEventArgs e) { string CodeLb = this.GVList.DataKeys[e.RowIndex].Values[0].ToString(); string CodeValue = this.GVList.DataKeys[e.RowIndex].Values[1].ToString(); SystemCodeBLL.Delete(CodeLb, CodeValue); //删除完之后重新绑定 this.Init_Data(ViewState["CodeLb"] == null ? "" : ViewState["CodeLb"].ToString()); }
BLL层:
- C# code
// 新增 public void Add(SystemCodeModel Model) { DAL.Add(Model); } //修改 public void Update(SystemCodeModel Model) { DAL.Update(Model); } //删除 public void Delete(string CodeLb, string CodeValue) { DAL.Delete(CodeLb, CodeValue); }
DAL层:
- C# code
//引用微软企业库using Microsoft.Practices.EnterpriseLibrary.Data;using Microsoft.Practices.EnterpriseLibrary.Common; //建立数据库访问类 Database db = DatabaseFactory.CreateDatabase(); // 新增 public void Add(SystemCodeModel Model) { System.Data.Common.DbCommand sqlCommand = db.GetStoredProcCommand("SystemCode_ADD"); db.AddInParameter(sqlCommand, "CodeLb_in", DbType.String, Model.CodeLb); db.AddInParameter(sqlCommand, "LbName_in", DbType.String, Model.LbName); db.AddInParameter(sqlCommand, "CodeValue_in", DbType.String, Model.CodeValue); db.AddInParameter(sqlCommand, "CodeName_in", DbType.String, Model.CodeName); db.ExecuteNonQuery(sqlCommand); } //修改 public void Update(SystemCodeModel Model) { System.Data.Common.DbCommand sqlCommand = db.GetStoredProcCommand("SystemCode_Update"); db.AddInParameter(sqlCommand, "CodeLb_in", DbType.String, Model.CodeLb); db.AddInParameter(sqlCommand, "LbName_in", DbType.String, Model.LbName); db.AddInParameter(sqlCommand, "CodeValue_in", DbType.String, Model.CodeValue); db.AddInParameter(sqlCommand, "CodeName_in", DbType.String, Model.CodeName); db.ExecuteNonQuery(sqlCommand); } //删除 public void Delete(string CodeLb, string CodeValue) { System.Data.Common.DbCommand sqlCommand = db.GetStoredProcCommand("SystemCode_Delete"); db.AddInParameter(sqlCommand, "CodeLb_in", DbType.String, CodeLb); db.AddInParameter(sqlCommand, "CodeValue_in", DbType.String, CodeValue); db.ExecuteNonQuery(sqlCommand); }