标题:[讨论]还是图片存取显示的问题,大家看看
取消只看楼主
独孤幽灵
Rank: 1
等 级:新手上路
帖 子:115
专家分:0
注 册:2005-11-24
 问题点数:0 回复次数:0 
[讨论]还是图片存取显示的问题,大家看看

//这是插入数据的代码
protected void Button1_Click(object sender, EventArgs e)
{
string ExName = string.Empty;
#region
if (FileSelect.PostedFile.FileName != null)
{
int filesize = FileSelect.PostedFile.ContentLength;//get the file of size
if (filesize > (500 * 1024) || filesize < 0)
{
Response.Write("<scirpt language='javascript'>alert('请确认图片存在且小于500K');</scirpt>");//大于500K或文件不存在时
}
else
{
try
{ //获取文件完整的路径及名称
string fullname = FileSelect.PostedFile.FileName.ToString();
//取得文件扩展名
ExName = fullname.Substring(fullname.LastIndexOf("."));

//一:利用时间生成新文件名(年+月+日+小时+分钟+秒+毫秒)
string NewName = DateTime.Now.Year.ToString() +
DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString();

//二:利用GUID结构生成唯一文件名
Guid myguid = Guid.NewGuid();
NewName += myguid.ToString();
NewName = NewName.Replace("-","");
NewName = NewName.ToUpper();

//为新文件加上扩展名
NewName += ExName;

//HttpRuntime.AppDomainAppPath获取站点跟目录的物理路径
FileSelect.PostedFile.SaveAs(HttpRuntime.AppDomainAppPath + @"UpLoad\" + NewName);

//insert into sql server
string cmdsql = "data source=.;database=TryPicture;Trusted_Connection=yes";

SqlConnection conn = new SqlConnection(cmdsql);
conn.Open();

string cmdtext = "insert into Blog_Picture(pictureSize,pictureupload,pictureName,pictureDatetime,pictureType) values (@picturesize,@pictureupload,@pictureName,@pictureDatetime,@picturetype)";

SqlCommand comm = new SqlCommand(cmdtext, conn);
comm.Parameters.Add("pictureupload", SqlDbType.NVarChar).Value = @"upload/" + NewName;
comm.Parameters.Add("pictureName", SqlDbType.VarChar).Value = txtTitle.Text.Trim();
comm.Parameters.Add("pictureDatetime", SqlDbType.DateTime).Value = DateTime.Now.ToString();
comm.Parameters.Add("pictureType",SqlDbType.Char).Value=ExName;
comm.Parameters.Add("pictureSize",SqlDbType.Int).Value=filesize;

comm.ExecuteNonQuery();

conn.Close();
Response.Write("<script language='javascript'>alert('记录添加成功');</script>");
}
catch (Exception error)
{
Response.Write(error.ToString());
}
}
}
#endregion
}

在数据库中查询图片路径的结果是这样的路径 upload/20073122095EIFJISIA987.gif



//下面是读取的代码
private DataSet Get_Picture()
{
string cmdtext = "select pictureupload from Blog_Picture";

SqlConnection connget = new SqlConnection(cmdsql);
connget.Open();

SqlDataAdapter da = new SqlDataAdapter(cmdtext, connget);

DataSet ds = new DataSet();
da.Fill(ds,"picture");
return ds;
}

用image控件 怎么显示图片,根据数据集中取出的的图片路径啊?

搜索更多相关主题的帖子: 存取 
2007-03-12 20:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-123883-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.115916 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved