update的方法是
SqlDataAdapter adapter= new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand();
adapter.SelectCommand.Connection = new SqlConnection(ConnectionString);adapter.SelectedCommand.CommadText="select * ......";
DataSet ds=new DataSet;
adapter.FillData(ds,"myTable");
.
.
.
.
adapter.Update(ds,"myTabel");问题是在很多情况下可能并不保留adapter的状态,例如在一个三层结构中,特别在使用webservice的时候,这时候adapter.Update(...)的adapter已经不是原来的adapter了,解决方法应该是有的,重新构建一个adapter2,重新Fill一个DataSet如ds2,然后把ds1的内容付给ds2,adapter.Update(ds2,"myTable"),但这样重新Fill这一步不是要花费时间浪费资源吗?有没有什么好的办法?
SqlDataAdapter adapter= new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand();
adapter.SelectCommand.Connection = new SqlConnection(ConnectionString);adapter.SelectedCommand.CommadText="select * ......";
DataSet ds=new DataSet;
adapter.FillData(ds,"myTable");
.
.
.
.
adapter.Update(ds,"myTabel");问题是在很多情况下可能并不保留adapter的状态,例如在一个三层结构中,特别在使用webservice的时候,这时候adapter.Update(...)的adapter已经不是原来的adapter了,解决方法应该是有的,重新构建一个adapter2,重新Fill一个DataSet如ds2,然后把ds1的内容付给ds2,adapter.Update(ds2,"myTable"),但这样重新Fill这一步不是要花费时间浪费资源吗?有没有什么好的办法?
adapter.SelectedCommand.CommadText="select * from 一个表 where 1=2";
或者用单件模式实现,不过没有必要,而前多线程情况下会出现connection正在被使用的问题,
建议使用Data Access block.
search that in msdn with "application block" as the key words
then download the data access application block and do an analysis
SqlConnection最好随用随关,
SqlConnection _conn = new SqlConnection( …… );
{
_conn.Open();
}
catch(Exception)
{
……
}
finally
{
_conn.Close();
}