主题:有关DataSet的使用问题?
初学C#;
以下一段程序,如在界面中直接写执行没问题。
我把它放在一个类中调用
dbsobj是有数据的并非null,
UpdateByDataSet(dbsobj,string strTblName,string strConnection)
出现'myAdapter.Update(ds,strTblName)'执行ds 未实例化
请问如何在调用涵数时传递 DataSet
public int UpdateByDataSet(DataSet ds,string strTblName,string strConnection)
{
try
{
SqlConnection conn = new SqlConnection(strConnection));
SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlCommand myCommand = new SqlCommand("select * from "+strTblName),(SqlConnection)this.conn);
myAdapter.SelectCommand = myCommand;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
myAdapter.Update(ds,strTblName);
return 0;
}
catch(BusinessException errBU)
{
throw errBU;
}
catch(Exception err)
{
throw new BusinessException(err);
}
}
以下一段程序,如在界面中直接写执行没问题。
我把它放在一个类中调用
dbsobj是有数据的并非null,
UpdateByDataSet(dbsobj,string strTblName,string strConnection)
出现'myAdapter.Update(ds,strTblName)'执行ds 未实例化
请问如何在调用涵数时传递 DataSet
public int UpdateByDataSet(DataSet ds,string strTblName,string strConnection)
{
try
{
SqlConnection conn = new SqlConnection(strConnection));
SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlCommand myCommand = new SqlCommand("select * from "+strTblName),(SqlConnection)this.conn);
myAdapter.SelectCommand = myCommand;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
myAdapter.Update(ds,strTblName);
return 0;
}
catch(BusinessException errBU)
{
throw errBU;
}
catch(Exception err)
{
throw new BusinessException(err);
}
}