为什么不能删除数据库中的记录? 如果仅仅就这些代码,当然删不了了没有删除字符串阿用commandBuilder看看行不行 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 myAdapter.Fill(ds); //填充dsds.Tables[0].Rows.RemoveAt(1); //移除ds.Tables[0]中的内容myAdapter.Update(ds,"ReptFlt"); //修改ds.Tables[??]的内容, //并取名为表“ReptFlt”//ds是表的集合,里面有若干个表,ds.Tables[1]应该是你所要的表!! private void Page_Load(object sender, System.EventArgs e) { myAdapter.Fill(ds); ds.Tables["ReptFlt"].Rows.RemoveAt(1); myAdapter.Update(ds.ReptFlt); //修改成这样也不行 } 加一句ds.getchanges();当然,象一楼说的,要就这几句的话,数据都显示不出来,更别说删除什么了 《C#入门经典》清华大学出版社出版的书中491-492页中描述用DataSet中的数据更新在数据库中的数据,只用了一条语句:private void Button1_Click(){ this.sqlDataAdapter1.Update(this.dsCustomers1.Customers);}书中描述说:当单击按钮Button1时,对DataSet所作的任何变动都会传递到数据库。 晕,你的sqlDataAdapter什么都没有帮定,也就是说你的让它知道你操作的是那个数据库,执行的是什么命令亚,就是需要有SqlCommand的前提才是数据操作的基础 完整删除数据代码为:DialogResult result; string message = "注意,删除雇员信息将不可恢复,您真的要删除么?"; string caption = "提示"; MessageBoxButtons btn = MessageBoxButtons.YesNo; MessageBoxIcon ico = MessageBoxIcon.Information; result = MessageBox.Show(this, message, caption, btn, ico); if (result == DialogResult.Yes) { conncetion c = new conncetion(); OleDbCommand cmd = new OleDbCommand("删除雇员", c.con());//为存储过程类型 cmd.CommandType = CommandType.StoredProcedure try { ; cmd.Parameters.Add("@gzz", OleDbType.VarChar, 50); cmd.Parameters["@gzz"].Value = textBox7.Text.Trim(); if (cmd.ExecuteNonQuery() != 0) { MessageBox.Show("删除成功", "恭喜 "); tabControl1.SelectedIndex = 0; fenye(); } else { MessageBox.Show("有参数错误", "出错啦"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "出错啦"); } finally { c.con().Close(); }//删除语句字符串格式为DELETE FROM TABLENAME WHERE(ComlumnName=@comlumnname); ds.Tables["ReptFlt"].Rows.RemoveAt(3);改成ds.Tables["ReptFlt"].Rows[3].delete() ds.Tables["ReptFlt"].Rows.RemoveAt(3);改成ds.Tables["ReptFlt"].Rows[3].delete() 求助画一个控件 类的继承!!不懂,请教下 一个小程序,看不太懂,帮忙。 c# 如何改变页面属性使地址栏以上的部分都不可见 用了try-catch为何还会出错 SQL语句可以写多长 C#如何查询数据库中某行的某列? [求助]C#(WinForm)DataGrid表格里能放TextBox吗? 我刚学完.net,想做一个qq,怎样才能把QQ的图标做到状态栏右下脚的时钟旁边呀! 在调用 SQLDMO.Application 的一个方法时出错了。 c#数据库 小小问题,可难倒我了!
//并取名为表“ReptFlt”
//ds是表的集合,里面有若干个表,ds.Tables[1]应该是你所要的表!!
{
myAdapter.Fill(ds);
ds.Tables["ReptFlt"].Rows.RemoveAt(1);
myAdapter.Update(ds.ReptFlt); //修改成这样也不行
}
private void Button1_Click()
{
this.sqlDataAdapter1.Update(this.dsCustomers1.Customers);
}
书中描述说:当单击按钮Button1时,对DataSet所作的任何变动都会传递到数据库。
string message = "注意,删除雇员信息将不可恢复,您真的要删除么?";
string caption = "提示";
MessageBoxButtons btn = MessageBoxButtons.YesNo;
MessageBoxIcon ico = MessageBoxIcon.Information;
result = MessageBox.Show(this, message, caption, btn, ico);
if (result == DialogResult.Yes)
{
conncetion c = new conncetion();
OleDbCommand cmd = new OleDbCommand("删除雇员", c.con());//为存储过程类型
cmd.CommandType = CommandType.StoredProcedure
try
{
;
cmd.Parameters.Add("@gzz", OleDbType.VarChar, 50);
cmd.Parameters["@gzz"].Value = textBox7.Text.Trim();
if (cmd.ExecuteNonQuery() != 0)
{
MessageBox.Show("删除成功", "恭喜 ");
tabControl1.SelectedIndex = 0;
fenye();
}
else
{
MessageBox.Show("有参数错误", "出错啦");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "出错啦");
}
finally
{
c.con().Close();
}
//删除语句字符串格式为
DELETE FROM TABLENAME WHERE(ComlumnName=@comlumnname);