http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchtopquestionsaboutaspnetdatagridservercontrol.aspEditing Multiple Rows At Once

解决方案 »

  1.   

    private void btnUpdate_Click(object sender, System.EventArgs e)
    {
       int i;
       DataGridItem dgi;
       int bookid;
       TextBox TextBoxTitle;
       CheckBox CheckBoxInStock;
       TextBox TextBoxPrice;   for(i = 0; i <= DataGrid1.Items.Count -1 ; i++)
       {
          dgi = DataGrid1.Items[i];
          Label LabelBookId = (Label) dgi.Cells[0].Controls[1];
          bookid = int.Parse(LabelBookId.Text);
          TextBoxTitle = (TextBox) dgi.FindControl("TextBoxTitle");
          CheckBoxInStock = (CheckBox) dgi.FindControl("CheckBoxInStock");
          TextBoxPrice = (TextBox) dgi.FindControl("TextBoxPrice");
          this.dcmdUpdateBooks.Parameters["@bookid"].Value = bookid;
          this.dcmdUpdateBooks.Parameters["@Title"].Value = TextBoxTitle.Text;
          this.dcmdUpdateBooks.Parameters["@instock"].Value = 
    CheckBoxInStock.Checked;
          this.dcmdUpdateBooks.Parameters["@Price"].Value = 
    float.Parse(TextBoxPrice.Text);
          this.sqlConnection1.Open();
          this.dcmdUpdateBooks.ExecuteNonQuery();
          this.sqlConnection1.Close();
       }
    }
      

  2.   

    详情见http://dev.csdn.net/develop/article/27/27256.shtm
      

  3.   

    private void btnUpdate_Click(object sender, System.EventArgs e)
    {
       int i;
       DataGridItem dgi;
       int bookid;
       TextBox TextBoxTitle;
       CheckBox CheckBoxInStock;
       TextBox TextBoxPrice;   for(i = 0; i <= DataGrid1.Items.Count -1 ; i++)
       {
          dgi = DataGrid1.Items[i];
          Label LabelBookId = (Label) dgi.Cells[0].Controls[1];
          bookid = int.Parse(LabelBookId.Text);
          TextBoxTitle = (TextBox) dgi.FindControl("TextBoxTitle");
          CheckBoxInStock = (CheckBox) dgi.FindControl("CheckBoxInStock");
          TextBoxPrice = (TextBox) dgi.FindControl("TextBoxPrice");
          this.dcmdUpdateBooks.Parameters["@bookid"].Value = bookid;
          this.dcmdUpdateBooks.Parameters["@Title"].Value = TextBoxTitle.Text;
          this.dcmdUpdateBooks.Parameters["@instock"].Value = 
    CheckBoxInStock.Checked;
          this.dcmdUpdateBooks.Parameters["@Price"].Value = 
    float.Parse(TextBoxPrice.Text);
          this.sqlConnection1.Open();
          this.dcmdUpdateBooks.ExecuteNonQuery();
          this.sqlConnection1.Close();
       }
    }
      

  4.   

    简单,数据集合用DATASET,先修改到DATASET,然后DATASET 执行更新数据库的操作就OK了
      

  5.   

    TO:zxn1979125(钝刀) .能不能给点具体代码呢?
      

  6.   

    还是COMMAND好一点,DATASET.UPDATA有点问题
      

  7.   

    string strOleDb="select * from UserTable";
    // OleDbDataAdapter objCmd=new OleDbDataAdapter(strOleDb,Conn.Connection);
    // objCmd.Fill(ds,"usertable");
    //
    // string strOleDb1="select * from userinfotable";
    // OleDbDataAdapter objCmd1=new OleDbDataAdapter(strOleDb1,Conn.Connection);
    // objCmd1.Fill(ds,"userinfotable");
    //
    // DataTable objTable=ds.Tables["usertable"];
    // DataRow newRow1=objTable.NewRow();
    // newRow1["username"]=""+TextBox1.Text.ToString()+"";
    // newRow1["password"]=""+TextBox2.Text.ToString()+"";
    // newRow1["usertype"]="C";
    // newRow1["usercount"]="10";
    // objTable.Rows.Add(newRow1);
    //
    // DataTable objTable2=ds.Tables["userinfotable"];
    // DataRow newRow=objTable2.NewRow();
    // newRow["username"]=""+TextBox1.Text.ToString()+"";
    // newRow["userinfo"]=""+TextBox3.Text.ToString()+"";
    // newRow["email"]=""+TextBox4.Text.ToString()+"";
    // newRow["verityname"]=""+TextBox5.Text.ToString()+"";
    // newRow["birthday"]=""+TextBox6.Text.ToString()+DropDownList1.SelectedItem.Value+DropDownList2.SelectedItem.Value+"";
    // newRow["sex"]=""+DropDownList3.SelectedItem.Value+"";
    // newRow["province"]=""+TextBox7.Text.ToString()+"";
    // newRow["address"]=""+TextBox8.Text.ToString()+"";
    // newRow["postcode"]=""+TextBox9.Text.ToString()+"";
    // newRow["phone"]=""+TextBox10.Text.ToString()+"";
    // newRow["trade"]=""+DropDownList5.SelectedItem.Text+"";
    // newRow["shenfz"]=""+shenfen.Text.ToString()+"";
    // newRow["question"]=""+question.Text.ToString()+"";
    // newRow["answer"]=""+answer.Text.ToString()+"";
    // newRow["country"]=""+DropDownList4.SelectedItem.Text+"";
    // objTable2.Rows.Add(newRow);
    //
    // OleDbCommandBuilder buider1=new OleDbCommandBuilder(objCmd);
    // objCmd.UpdateCommand=buider1.GetUpdateCommand();
    // objCmd.Update(ds,"usertable");
    //
    // OleDbCommandBuilder buider2=new OleDbCommandBuilder(objCmd1);
    // objCmd1.UpdateCommand=buider2.GetUpdateCommand();
    // objCmd1.Update(ds,"userinfotable");
    // Conn.Close();
      

  8.   

    未将对象引用设置到对象的实例。 
    OleDbCommand myCommand = new OleDbCommand();
    行 140: this.myCommand.Parameters["@gcbm"].Value =Textgcbm.Text ;
    这个错误事什么?
      

  9.   

    this.dcmdUpdateBooks.Parameters["@bookid"].Value = bookid;中的["@bookid"]是什么呀?
      

  10.   

    1、按如下示例方法建立DataSet对象
    SqlDataAdapter adapter =
        new SqlDataAdapter ("select * from titles",
        "server=localhost;database=pubs;uid=sa;pwd=");SqlCommandBuilder builder = new SqlCommandBuilder (adapter);
    DataSet ds = new DataSet ();
    adapter.Fill (ds, "Titles");
    2、绑定到DataGrid
    DataGrid1.DataSource = ds;
    DataGrid1.DataBind ();
    3、在DataGrid中进行记录修改,完成后调用:
    adapter.Update (ds);
      

  11.   

    dagagrdi用文本框,绑定dataset后,直接在文本框编辑,可以多行编辑,然后点保存按钮把数据更新回数据库?
    谁能给点具体代码,我是新手啊,再加分!谢谢了哦