面页中如何调用后台一个操作类的方法
操作类部分代码:
public class operate
{
private SqlConnection con;
private SqlDataAdapter da;
private DataSet ds;
private DataTable dt;
private SqlCommandBuilder cb;
private DataRow dr;
public DataTable delete(string sql,DataRow dr)
{
da=new SqlDataAdapter(sql,createConn());
ds=new DataSet();
da.Fill(ds);
dt=ds.Tables[0];
return dt;
dr.Delete();
cb=new SqlCommandBuilder(da);
da.Update(ds);
}
}
面页后台部分代码:
public class WebForm1 : System.Web.UI.Page
{
private string sql= "select * from xs ";
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
operate op=new operate();
DataTable dt=op.delete(sql,dr);
DataRow dr=dt.Rows[e.Item.ItemIndex];
op.delete(sql,dr);
}
}
问题出在如果想在面页中调用操作类的delete()方法,必须给其传参数dr,但dr又必须依靠delete()的返回值来获得.结果就搞混了.高手支招.要求必须在操作类使用commandbuilder删除/更新dataset.不可以在操作类直接用SQL语句或用dataadapter的updatecommand()方法进行.
------解决方案--------------------
结贴!