RowUpdating代码哪里出错了提示成功但是没有更新数据库 - 爱问答

(爱问答)

RowUpdating代码哪里出错了提示成功但是没有更新数据库

try

        {

            SqlConnection conn = new SqlConnection();

            string connStr = "server=.;uid=sa;database=db_user;pwd=123;MultipleActiveResultSets=true;Integrated Security=true;";

            conn.ConnectionString = connStr;

            conn.Open();

            SqlCommand cmd = new SqlCommand();

            string xingming = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text;

            string riqi = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text;

            string chuqinjilu = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text;

            string id = GridView1.DataKeys[e.RowIndex].Value.ToString();

            string sql = "update tb_chuqin set username='" + xingming + "',date='" + riqi + "',attendance='" + chuqinjilu + "'where id=" + id;

            cmd.CommandText = sql;

            cmd.Connection = conn;

            if (cmd.ExecuteNonQuery() > 0)

            {

                Response.Write("<script>alert('更新成功');</script>");

            }

            else

            {

                Response.Write("<script>alert('更新失败');</script>");

            }

            GridView1.EditIndex = -1;

            show();

            conn.Close();

        }

        catch (Exception e1)

        {

            Response.Write(e1.Message);

        }


这种测试你可以考虑手动修改数据库里的信息,然后看看显示的信息有没有更改。要知道,有时候没有更新的意思是:update student set StudentName=@StudentName where studentID=@studentID"根据你的这条指令,没有产生更新的意思。你手动修改下studentID=@studentID 的StudentName项,改成随便的名字。再运行这个按钮,你看变不变。

相关标签:数据库

下一篇:我国的国标码将汉字编码采用__________位二进制进行编码,共收集了7445个汉字

上一篇:分布式通信系统是在什么背景下产生的

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?