怎么在datagrid中一次编辑多条记录,并同时提交到数据库呢? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchtopquestionsaboutaspnetdatagridservercontrol.aspEditing Multiple Rows At Once 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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(); }} 详情见http://dev.csdn.net/develop/article/27/27256.shtm 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(); }} 简单,数据集合用DATASET,先修改到DATASET,然后DATASET 执行更新数据库的操作就OK了 TO:zxn1979125(钝刀) .能不能给点具体代码呢? 还是COMMAND好一点,DATASET.UPDATA有点问题 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(); 未将对象引用设置到对象的实例。 OleDbCommand myCommand = new OleDbCommand();行 140: this.myCommand.Parameters["@gcbm"].Value =Textgcbm.Text ;这个错误事什么? this.dcmdUpdateBooks.Parameters["@bookid"].Value = bookid;中的["@bookid"]是什么呀? 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、绑定到DataGridDataGrid1.DataSource = ds;DataGrid1.DataBind ();3、在DataGrid中进行记录修改,完成后调用:adapter.Update (ds); dagagrdi用文本框,绑定dataset后,直接在文本框编辑,可以多行编辑,然后点保存按钮把数据更新回数据库?谁能给点具体代码,我是新手啊,再加分!谢谢了哦 girdview控件中datetime类型的数据格式问题 想了一个晚上也想不通!!求了 分批读取数据,有谁做过,类似Sql的select的显示。 高分求报错Volitant.WebShared.Module Not Config的原因 请大伙来看看我的SQL语句问题!顶这有分!不够+++!SOS 如何实现页面部分自动刷新? ASP.NET2.0中动态给角色分配权限的问题 如何使 linkbutton禁用。 如何在asp.net中将报表输出到excel中(不用客户端代码, 不使用控件传递? .net能不能在线生成语音文件?? asp.net调用存储过程的参数必须和存储过程里的一样 初级问题
{
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();
}
}
{
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();
}
}
// 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();
OleDbCommand myCommand = new OleDbCommand();
行 140: this.myCommand.Parameters["@gcbm"].Value =Textgcbm.Text ;
这个错误事什么?
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);
谁能给点具体代码,我是新手啊,再加分!谢谢了哦