本文介绍了在存储图像路径时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,我想在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 asString 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...
推荐答案
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
.
这篇关于在存储图像路径时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!