IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo) (MethodInfo.GetCurrentMethod())),iD,fname, lname);
return (int)result.ReturnValue;
}
[Function(Name = "Employees_Delete")]
public int DeleteEmployee([Parameter(Name = "ID", DbType = "Int")] System.Nullable<int> iD)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo) (MethodInfo.GetCurrentMethod())), iD);
return (int)result.ReturnValue;
}
好了,方法创建好了,接下来就是在ASP.NET Web Form中对这些方法进行调用。
添加一个DetailsView 控件。对它进行数据的绑定,方法和(1)中的基本一样
private void BindDetailsView()
{
string strConn = ConfigurationManager.ConnectionStrings ["connstr"].ConnectionString;
NorthwindDb db = new NorthwindDb(strConn);
ISingleResult<Employee> results = db.GetAllEmployees();
DetailsView1.DataSource = results;
DetailsView1.DataBind();
}
利用DetailsView 控件对数据执行增加,删除,修改的操作
protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
string strConn = ConfigurationManager.ConnectionStrings ["connstr"].ConnectionString;
NorthwindDb db = new NorthwindDb(strConn);
db.UpdateEmployee((int)DetailsView1.SelectedValue,((TextBox) DetailsView1.Rows[1].Cells[1].Controls[0]).Text, ((TextBox)DetailsView1.Rows[2].Cells [1].Controls[0]).Text);
}
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
string strConn = ConfigurationManager.ConnectionStrings ["connstr"].ConnectionString;
NorthwindDb db = new NorthwindDb(strConn);
db.InsertEmployee(((TextBox)DetailsView1.Rows[1].Cells[1].Controls [0]).Text, ((TextBox)DetailsView1.Rows[2].Cells[1].Controls[0]).Text);
}
protected void DetailsView1_ItemDeleting(object sender, DetailsViewDeleteEventArgs e)
{
string strConn = ConfigurationManager.ConnectionStrings ["connstr"].ConnectionString;
NorthwindDb db = new NorthwindDb(strConn);
db.DeleteEmployee((int)DetailsView1.SelectedValue);
}
这样通过存储过程对数据操作就搞定了。
本文配套源码
|