关于vs08删除的问题,只想问问有没有人遇到过,来了就有分

zhangsuyunpk521 2010-07-22 02:29:49
try
{
int classID = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex]["cid"].ToString());
String sqlStr = "delete from nclass where cid=@cid ";
SqlCommand cmd = new SqlCommand(sqlStr, conn);
cmd.Parameters.Add("@cid", SqlDbType.Int, 4);
cmd.Parameters["@cid"].Value = classID;
conn.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
bind();
}
else
{
message("服务器忙");
}
conn.Close();
}
catch
{
throw;
}
我这样删除有一个问题,就是当我点删除的删除成功了他也会执行else里面的代码
后来我打断点之后发现,点一次删除它执行了2次,第一次删除成功后,就接着执行第二次删除,这样当然不会有数据让他删除了,有没有谁遇到过这种问题,有的话说一下怎么解决,我用VS05的时候就没有这个问题,难道是我用08打开的时候转换出了问题?
...全文
100 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangsuyunpk521 2010-07-22
  • 打赏
  • 举报
回复
按2楼的方法就正确了,但是按道理说不用finally部分这样写也不会错啊,为什么会出现在中情况,难道是vs设置的问题,好了,看看有没有人遇到过这种情况,准备结贴了!~~~
sywcf 2010-07-22
  • 打赏
  • 举报
回复
楼主应该贴出来更多的代码,或这段代码你是写在哪个方法里了,单看这个没什么问题
zhangsuyunpk521 2010-07-22
  • 打赏
  • 举报
回复
代码放在GridView1_RowDeleting里面在啊
zhangsuyunpk521 2010-07-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zjtpiaoxue 的回复:]
int i = 0;
try
{
int classID = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex]["cid"].ToString());
String sqlStr = "delete from nclass where cid=@cid ";
SqlCommand cmd = new SqlComman……
[/Quote]
不是,我打断点看的情况是,就像我这段代码写在for循环里面一样,执行次数是2次
sywcf 2010-07-22
  • 打赏
  • 举报
回复
应该和这段代码没关系,楼主看下是不是别处调用了
yulei243007703 2010-07-22
  • 打赏
  • 举报
回复
我想是跟这段代码没有什么关系,应该是把这段代码放在什么地方执行有关系
lfr562330262 2010-07-22
  • 打赏
  • 举报
回复
学习 学习
辰爸 2010-07-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 zhangsuyunpk521 的回复:]
try
{
int classID = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex]["cid"].ToString());
String sqlStr = "delete from nclass where cid=@cid ";
SqlCommand cmd = new S……
[/Quote]
楼主说的执行两次是什么情况,一次性的执行两条删除语句吗?
zjtpiaoxue 2010-07-22
  • 打赏
  • 举报
回复
int i = 0;
try
{
int classID = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex]["cid"].ToString());
String sqlStr = "delete from nclass where cid=@cid ";
SqlCommand cmd = new SqlCommand(sqlStr, conn);
cmd.Parameters.Add("@cid", SqlDbType.Int, 4);
cmd.Parameters["@cid"].Value = classID;
conn.Open();
i = cmd.ExecuteNonQuery();
catch
{
throw;
}
finally
{
if (i > 0)
{
bind();
}
else
{
message("服务器忙");
}
conn.Close();
}

}
zhangsuyunpk521 2010-07-22
  • 打赏
  • 举报
回复
自己先涨下人气先!~~

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧