zoukankan      html  css  js  c++  java
  • 通过强类型DataSet更新数据的问题。

    请先看下面的代码( DataSet1为一强类型DataSet. )


       DataSet1 ds1 = new DataSet1();   

       SqlConnection conn = new SqlConnection();
       conn.ConnectionString = @".....";
       
       conn.Open();

       SqlCommand comm = new SqlCommand();
       comm.CommandType = CommandType.Text;
       comm.CommandText = "select * from article where ariticle_id < 0";//这里!让选择的结果集为空是可行的! 这样可以提高效率。但是这个语句一定要写,还不能写为"",并且要把结果Fill到ds1中。
       comm.Connection = conn;

       SqlDataAdapter adapter = new SqlDataAdapter();
       adapter.SelectCommand = comm;

       SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
      
       adapter.Fill(ds1,ds1.Article.TableName);


       DataSet1.ArticleRow drNew = ds1.Article.NewArticleRow();
       drNew.Ariticle_ID = int.Parse(this.TextBox1.Text);
       drNew.User_ID = int.Parse(this.TextBox2.Text);
       drNew.Title = this.TextBox3.Text;
       drNew.Content = this.TextBox4.Text;
       drNew.AddTime = DateTime.Now;
       drNew.CheckTime = DateTime.Now;
       drNew.ViewCount = int.Parse(this.TextBox5.Text);

       ds1.Article.AddArticleRow(drNew);


       adapter.Update(ds1,ds1.Article.TableName);//插入或更新.

    问题是:

    1> 为什么还需要先select一个结果集,然后邦定到ds1,然后操作ds1,更新ds1? 


    “先select一个结果集”:我们可以故意让结果为0条记录,既然这样,还需要这个作什么用?Ado.Net这样的设计,让人觉得不舒服!


    2> 有其他通过DataSet刷新数据的“看起来比较正常的”方法吗?

  • 相关阅读:
    jQuery中jsonp的跨域处理,no access-control-allow-origin,unexpected token
    doT中嵌套for循环的使用
    c++ new带括号和不带括号
    python装饰器之使用情景分析
    Python中classmethod与staticmethod区别
    python作用域 scope
    duck type鸭子类型
    EAFP和LBYL 两种防御性编程风格
    c++重载、覆盖和隐藏
    c++ 名字粉碎(name mangling)
  • 原文地址:https://www.cnblogs.com/silva/p/541923.html
Copyright © 2011-2022 走看看