高分求asp.net(C#)将图片保存到数据库(SQL2000)代码!

lib_zhang 2005-01-31 04:51:57
如题,图片格式包括GIF、BMP、JPG等等,保存到数据库Image中!
...全文
320 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
fan1223 2005-06-01
  • 打赏
  • 举报
回复
a
sword222 2005-02-01
  • 打赏
  • 举报
回复
1、先上传图片到你指定的文件夹,并对你上传的图片进行命名(要注意不要重复),然后在把图片的路径保存到数据库。(一般的操作)
2、也可以用二进制流把图片保存到数据库里面

具体操作的代码你搜索一下,很多的
ybh2002 2005-02-01
  • 打赏
  • 举报
回复
//写入图片到数据库中
private void WriteImage()
{
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "insert into images(image,type) values(@image,@type)";
comm.CommandType = CommandType.Text;
SqlParameter param = comm.Parameters.Add("@image",SqlDbType.Image);
param.Value = ReadFile();
param = comm.Parameters.Add("@type",SqlDbType.NVarChar);
param.Value = GetContentType(new FileInfo(fileName).Extension.Remove(0,1));

if(comm.ExecuteNonQuery() == 1)
Response.Write("Successful");
else
Response.Write("Fail");

conn.Close();
}

//获取图片的后缀名
private string GetContentType(string extension)
{
string type = "";

if(extension.Equals("jpg") || extension.Equals("JPG"))
type = "jpeg";
else
type = extension;

return "image/"+type;
}
老鹰40 2005-02-01
  • 打赏
  • 举报
回复
up
minghui000 2005-02-01
  • 打赏
  • 举报
回复
up
ldljlq 2005-01-31
  • 打赏
  • 举报
回复
Google上搜索一下,大把。

dzvsyt 2005-01-31
  • 打赏
  • 举报
回复
顶一下,我只知道VB的
yyne 2005-01-31
  • 打赏
  • 举报
回复
up
yanyzty 2005-01-31
  • 打赏
  • 举报
回复
偶给你

//存储图片流
byte[] buffer;



// Extract out the name of the file an use it for the name
// of the photo
// string strName = System.IO.Path.GetFileNameWithoutExtension(file);

// Insert the image into the database and add it to the tree


if (frm_infoList.numberfee ==null)
{
if(file==null)
{
MessageBox.Show ("相片不能为空!","提示",MessageBoxButtons.OK ,MessageBoxIcon.Information );
return;
}
System.IO.FileStream stream = new System.IO.FileStream(file,
System.IO.FileMode.Open,
System.IO.FileAccess.Read);
// Create a buffer to hold the stream bytes
buffer = new byte[stream.Length];
// Read the bytes from this stream
stream.Read(buffer, 0, (int)stream.Length);
// Now we can close the stream
stream.Close();
cm.Parameters ["@photo"].Value =buffer;
}
else
{
if(modPhoto)
{
if(file==null)
{
MessageBox.Show ("相片不能为空!","提示",MessageBoxButtons.OK ,MessageBoxIcon.Information );
return;
}
System.IO.FileStream stream = new System.IO.FileStream(file,
System.IO.FileMode.Open,
System.IO.FileAccess.Read);
// Create a buffer to hold the stream bytes
buffer = new byte[stream.Length];
// Read the bytes from this stream
stream.Read(buffer, 0, (int)stream.Length);
// Now we can close the stream
stream.Close();
cm.Parameters ["@photo"].Value =buffer;
}
else

cm.Parameters ["@photo"].Value =b;
}
cm.ExecuteNonQuery ();
lx4587 2005-01-31
  • 打赏
  • 举报
回复
晕,这还用找,保存图片的路径一切就都OK了!
lib_zhang 2005-01-31
  • 打赏
  • 举报
回复
有C#的吗?
liulxmooo 2005-01-31
  • 打赏
  • 举报
回复
up
michaelowenii 2005-01-31
  • 打赏
  • 举报
回复
这里的代码已经多的泛滥了,你找一下吧。。。。
warren1999 2005-01-31
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc/ShowDetail.aspx?id=2A5DD7C6-A45A-48AB-A2E8-342A29F17506
hedonister 2005-01-31
  • 打赏
  • 举报
回复
先插入基本信息项,常规操作不用说了吧?

再把图片转成二进制 比如:image

用UPDATEBLOB 表名 SET 图片字段 = image WHERE 条件

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧