在存储图像路径时遇到问题 [英] having problem in storing image path
本文介绍了在存储图像路径时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,我想在images文件夹中上传图片,并在数据库中存储图片路径.
通过使用中继器,我想显示上传的图像
我发现错误为
String or binary data would be truncated. The statement has been terminated
我的代码是
hi friends i want to upload image in images folder and store image path in database.
by using repeater i want to show the uploaded images
i found error as
String or binary data would be truncated. The statement has been terminated
my code is
protected void BtnSave_Click(object sender, EventArgs e)
{
if(Fileup.HasFile)
{
try
{
string path=Server.MapPath("~/images//"+Fileup.FileName);
Fileup.SaveAs(path);
Label3.Text = "Upload succesfully";
con.Open();
string command1 = "insert into gallery (galleryimage) values (''" + path + "'')";
SqlCommand cmd1 = new SqlCommand(command1, con);
cmd1.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
Label3.Text="error"+ex.Message.ToString();
}
}
}
public void bind2()
{
con.Open();
SqlDataAdapter da1 = new SqlDataAdapter("select * from gallery", con);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
Rp1.DataSource = dt1;
Rp1.DataBind();
}
protected void Viewfile_Click(object sender, EventArgs e)
{
bind2();
}
找到解决方案...
find the solution...
推荐答案
当您尝试插入一个字符串(或二进制)且其字符数超出了该列所能容纳的最大字符数时,会出现String or binary data would be truncated
消息.尝试将SQL数据库中列的长度更改为VARCHAR(MAX)
或您认为合适的长度.
问候
Hi,
you getString or binary data would be truncated
message when you try to insert a string (or binary) with more characters than the column can maximal accommodate. Try changing the length of the column in you SQL database toVARCHAR(MAX)
or to a length that you find suitable.
Regards
当您尝试将数据插入varchar字段并且数据长度大于Field Length时,会发生此问题.
因此,请检查路径长度和数据库字段长度.
问候
AR
Hi,
this problem occurs when you are trying to insert data into a varchar field and data length is greater than Field Length.
So please check the path length and Database field length.
Regards
AR
当您插入的字符串长度大于数据库中指定的长度时,将发生此错误.
例如..
如果您有列
This error comes when u r inserted string length is greater than ur specified length in database.
for example..
IF u have column
TITLE with varchar(5)
如果您在此列中插入
If in this column ur inserting
''codeprojectforums''
,则您将在您的字段中得到ur指定的错误,作为ur
then u will get ur specified error as ur
inserting more than 5 characters
.
这篇关于在存储图像路径时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文