我想使用Sql Update Query更新照片,而我是Usgin Fileupload Control [英] I Want To Update A Photo Using Sql Update Query And I Am Usgin Fileupload Control

查看:65
本文介绍了我想使用Sql Update Query更新照片,而我是Usgin Fileupload Control的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的按钮点击代码如下。照片未更新



My on button click code is as below. photo is not updating

 protected void updatecompany_Click(object sender, EventArgs e)
{
            SqlConnection con = new SqlConnection("xyz...");
            con.Open();
string filepath = Server.MapPath("~/CompanyLogo/" + strFileName);
            string path = "~/CompanyLogo/" + strFileName;

            string str = "UPDATE Table1 set CompanyLogo='" + path +"'   where CompanyID=" + Convert.ToInt16(Request.QueryString["CompanyID"].ToString());

 SqlCommand cmd = new SqlCommand(str, con);
            cmd.ExecuteNonQuery();
            con.Close();
        }

推荐答案

首先,停止访问这样的SQL!不要连接字符串以构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。改为使用参数化查询。



接下来要做的是检查你的QueryString返回值:如果它是错误的,或者为空,那么SQL将找不到任何匹配的记录并且不会更新任何内容。



我还会检查ExecuteNonQuery的返回值 - 如果它不是一个,那么它没有做你想要的和您需要尽可能多地尝试报告或记录问题。
First off, stop accessing SQL like that! 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.

The next thing to do is check your QueryString return value: if it is wrong, or empty, then the SQL will not find any matching records and will not update anything.

I'd also check the return value from ExecuteNonQuery - if it isn't one, then it didn't do what you wanted and you need to try to report or log the problem with as many details as you can.


这篇关于我想使用Sql Update Query更新照片,而我是Usgin Fileupload Control的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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