各位大侠帮我看看我的updata()命令错误在哪里,我运行没有错,就是数据表不能更新,是什么原因啊?代码如下:
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.Button1_Click(source,e); //更新数据库中的信息
string strTblName=this.DropDownList1.SelectedItem.Text.Trim(); //记录当前操作表的名字
DataRow dr=this.dataSet11.Tables[strTblName].Rows[(int)e.Item.ItemIndex]; //声明一个DataRow对象
for(int i=0;i<e.Item.Cells.Count-2;i++) //逐列更新数据
{
if(dr[i].GetType().Name.Equals("Int32"))
dr[i]=Int32.Parse(((TextBox)e.Item.Cells[i+2].Controls[0]).Text);
else if(dr[i].GetType().Name.Equals("float"))
dr[i]=float.Parse(((TextBox)e.Item.Cells[i+2].Controls[0]).Text);
else if(dr[i].GetType().Name.Equals("Decimal"))
dr[i]=Decimal.Parse(((TextBox)e.Item.Cells[i+2].Controls[0]).Text);
else
dr[i]=e.Item.Cells[i+2].Text.Trim();
}
this.sqlDataAdapter1.Update(this.dataSet11,strTblName); //更新数据库
this.DataGrid1.EditItemIndex=-1; //重新加载数据
this.Button1_Click(source,e);
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.Button1_Click(source,e); //更新数据库中的信息
string strTblName=this.DropDownList1.SelectedItem.Text.Trim(); //记录当前操作表的名字
DataRow dr=this.dataSet11.Tables[strTblName].Rows[(int)e.Item.ItemIndex]; //声明一个DataRow对象
for(int i=0;i<e.Item.Cells.Count-2;i++) //逐列更新数据
{
if(dr[i].GetType().Name.Equals("Int32"))
dr[i]=Int32.Parse(((TextBox)e.Item.Cells[i+2].Controls[0]).Text);
else if(dr[i].GetType().Name.Equals("float"))
dr[i]=float.Parse(((TextBox)e.Item.Cells[i+2].Controls[0]).Text);
else if(dr[i].GetType().Name.Equals("Decimal"))
dr[i]=Decimal.Parse(((TextBox)e.Item.Cells[i+2].Controls[0]).Text);
else
dr[i]=e.Item.Cells[i+2].Text.Trim();
}
this.sqlDataAdapter1.Update(this.dataSet11,strTblName); //更新数据库
this.DataGrid1.EditItemIndex=-1; //重新加载数据
this.Button1_Click(source,e);
解决方案 »
- 如果有两个Form页面,在Form2中增加一条数据时,怎样才能使Form1的状态发生改变
- 关于扫描器把二维条码输入textbox的问题,在线等
- 能将数组的下标设为字符串么?
- asp.net如何做出论坛那种列表
- DataGridViewComboBoxCell的问题
- 如何始终监视数据库中某一个字段的变化?
- C#調用C++寫的DLL問題,急
- 请问那种在统计当前光标在文本框里处于第几行第几列的效果是怎么做的?谢谢!
- c#.net的字符串问题,困扰我很久了,希望大虾解决一下。
- 如何确保只有一个????
- 获得Sql表结构的问题,会玩Sql server2000的进来出出主意!
- 怎样把doc文件传到数据库,然后从数据库读出doc文件呢
这叫重新加载数据?
再把Grid.Bind()一次吧
可能数据库已经有数据了,就是没有显示出来而已
用DataGrid的Updata() 再WEB页面更新数据库没这么复杂啊
你加我QQ 把 我们具体谈谈 83434829
this.dataSet11.AcceptChange();
没有这个方法,数据集并没有更新,所以你的数据库不会更新记录.
另外提示:你在执行button1_click的时候可以这样写
this.button1.PerformClick();不需要加入那些参数了
this.dataSet11.AcceptChange();将更新保存到Datasetthis.sqlDataAdapter1.Update;将DateSet中的数据保存到数据库