protected void datasetsql() 
    {
        conn = classconn.databasestr();
        SqlConnection sqlconn = new SqlConnection(conn);
        SqlCommand cmd = new SqlCommand("c", sqlconn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@csql", SqlDbType.NVarChar);
        cmd.Parameters["@csql"].Value = "select * from us order by id desc";
        SqlDataAdapter ada = new SqlDataAdapter();
        DataSet ds = new DataSet();
        ada.SelectCommand = cmd;
        ada.Fill(ds, "us");
        DataRow rss = ds.Tables["us"].NewRow();
        rss["name"] = "name";
        rss["pwd"] = "password";
        rss["note"] ="note";
        rss["othernote"] = "othernote";
        rss["uid"] = 10;
        ds.Tables["us"].Rows.Add(rss);
        
        dg2.DataSource = ds;
        dg2.DataBind();
    }
这个我写dataset中不能插入数据,我写了插入但是数据没有插入到数据库中,,然后我写了一个ada.Update(ds, "us");,但是一执行的时候就显示""当传递具有新行的 DataRow 集合时,更新要求有效的 InsertCommand。""
请高手指点一下应该怎么办呢?

解决方案 »

  1.   

    还有就是我写了一个更新~
    ds.Tables["us"].Rows[1].BeginEdit();
            ds.Tables["us"].Rows[1]["name"] = "fanfan";
            ds.Tables["us"].Rows[1].EndEdit();
    我绑定的是datagrid控件,在显示出来的时候的确被更新了可是我到数据库里看了一下还是原来的内容,,请问这个问题和上面的问题应该怎么解决呢/?
    谢谢~~~~~`
      

  2.   

    你的帮定要写在
    if(!Page.IsPostBack)
             {         }
    你写了吗?
      

  3.   

    呵呵本题我已经解决  谢谢你 
    解决方法如下
    conn = classconn.databasestr();
            SqlConnection sqlconn = new SqlConnection(conn);
            SqlCommand cmd = new SqlCommand("c", sqlconn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@csql", SqlDbType.NVarChar);
            cmd.Parameters["@csql"].Value = "select * from us order by id desc";
            SqlDataAdapter ada = new SqlDataAdapter();
            DataSet ds = new DataSet();
            SqlCommandBuilder br = new SqlCommandBuilder(ada);   //主要是在这里添加了一行语句呵呵
            ada.SelectCommand = cmd;
            ada.Fill(ds, "us");
            ds.Tables["us"].Rows[1].Delete();
      

  4.   

    哦对了我在问个问题就是在asp.net中什么时候用[]号 什么时候用()号呢?
    我都整不明白了~~~
    有人帮我么 谢谢~~~~~
      

  5.   

    () 是 method [] 是 parameter