日期:2014-05-17  浏览次数:20861 次

dataset更新数据内容

    
    public class Class1
    {
        string str = "Data Source=.;Initial Catalog=MySchool;Integrated Security=True";

        public DataSet Fill(string str) {
            SqlConnection com = new SqlConnection(str);
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(str,com);
            sda.Fill(ds,"Student");
            return ds;
        }




建立一个类库,类库里是图片上的内容,返回一个dataset对象,现在又需要用到SqlCommanBuilder builder=new SqlCommandBuilder(已创建的adapter对象)更新数据,其中的Adapter对象如何获得。

------解决方案--------------------

 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);
 }

------解决方案--------------------