我的数据未更新 [英] My data is not updated

查看:92
本文介绍了我的数据未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的更新按钮代码

This is my update button code

protected void Save_Button_Click(object sender, EventArgs e)
       {
           if (Page.IsPostBack)
           {
               string Employee_id = Request.QueryString["Emp_Id"];
               SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UsersManagerConnectionString"].ConnectionString);
               con.Open();
               SqlCommand cmd = new SqlCommand("Update Employees Set First_Name='" + First_NamTextBox.Text + "' ,Last_Name='" + Last_NamTextBox.Text + "', Email='" + Email_TextBox.Text + "', Mobile_Number='" + Mobile_TextBox.Text + "' where Emp_Id='" + Employee_id + "'", con);
               int executequery = cmd.ExecuteNonQuery();
               if (executequery == 1) { Response.Redirect("MainAdmin.aspx"); }
               con.Close();
           }


       }



请帮帮我。


Help me please.

推荐答案

检查您的Employee_id值 - 我怀疑它与任何现有记录都不匹配。你没有显示加载它的位置,但我怀疑你会发现它是空的。



并且不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询。
Check your Employee_id value - I suspect it is not matching any existing records. You don''t show where you load it, but I suspect you will find it is empty.

And do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.


这篇关于我的数据未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆