执行非查询时出现问题 [英] Problem While Executing Non Query

查看:113
本文介绍了执行非查询时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

尝试运行我的应用程序时出现此错误.

Hi all!!

I am getting this Error when trying to run my application.

String or binary data would be truncated. The Statement has been Terminated



这是代码



this is the code

protected void btnUpload_Click(object sender, EventArgs e)
    {
        con.Open();
        string filename = FileUpload1.PostedFile.FileName;
        string path = "Upload/" + filename;
        SqlCommand cmd = new SqlCommand("Insert into Zoom(ImageName,ImagePath) values ('"+ filename +"','"+ path +"')", con);
        cmd.ExecuteNonQuery();
        FileUpload1.PostedFile.SaveAs(Server.MapPath("Upload/") + filename.Trim());
        con.Close();

    }




它在第一次运行时有效,但是此后又一次又一次向我显示错误.




it worked for the first run but after that it has been showing me error again and again.

推荐答案



调试您的应用程序,路径超出了您的表字段允许的字符.

希望增加允许的字段字符能解决您的问题

谢谢
-Amit.
Hi,

Debug your application, path is exceeding the your table field allowed characters.

hope increasing field allowed characters will resolve your issue

thanks
-Amit.


受保护的无效btnUpload_Click(对象发送者,EventArgs e)
{
试试
{
con.Open();
字符串文件名= FileUpload1.PostedFile.FileName;
字符串路径=上传/" +文件名;
SqlCommand cmd =新的SqlCommand(插入Zoom(ImageName,ImagePath)值(""+文件名+",""+路径+"''),con);
cmd.ExecuteNonQuery();
FileUpload1.PostedFile.SaveAs(Server.MapPath("Upload/")+ filename.Trim());
con.Close();
}
catch(Exception exp)
{
}

}


尝试使用此代码,可能对您有用...
protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
con.Open();
string filename = FileUpload1.PostedFile.FileName;
string path = "Upload/" + filename;
SqlCommand cmd = new SqlCommand("Insert into Zoom(ImageName,ImagePath) values (''"+ filename +"'',''"+ path +"'')", con);
cmd.ExecuteNonQuery();
FileUpload1.PostedFile.SaveAs(Server.MapPath("Upload/") + filename.Trim());
con.Close();
}
catch(Exception exp)
{
}

}


try this code, might work for you...


http://doitdotnet.wordpress.com/2011/12/16/uploading-a-file-using-fileuploadcontrol-to-sqlserver/[^]

check the above url.. It will solve your issue. You are trying to save the file in to a directory which doesn''t exists in the server so you are getting error.


这篇关于执行非查询时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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