怎样在数据库中添加图形文件 各位大哥帮帮忙~

camark 2003-08-19 12:11:17
现在在做一个人力资源管理的数据库 除了员工头像之外什么都搞定了~

要求是这样的:
可以从browse按钮中选取相应的员工登记照的文件(文件格式可以为jpg,tif,gif等等) 选定文件之后 可以在窗口中显示出来,最后通过insert update等sql语句把这个文件添加到数据库中。

我现在的问题是,1、不知道数据库中用什么类型的字段来标明图形文件
2、不知道在vs.net中怎么实现显示图片和browse的功能


麻烦那位做过类似东东的大哥帮忙 先谢谢了 ~~
...全文
26 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
雪狼1234567 2003-08-19
  • 打赏
  • 举报
回复
取得文件流及相关信息后存入数据库中

HttpPostedFile upFile = up_file.PostedFile;
int iFileLength = upFile.ContentLength;
Byte[] FileByteArray = new Byte[iFileLength];
Stream StreamObject = upFile.InputStream;
StreamObject.Read(FileByteArray, 0, iFileLength);
SqlConnection conn = new SqlConnection("server=yy;uid=sa;pwd=;database=pany");
string sql = "insert into t_imgs (imgData, type, description, imgSize) values "
+ "(@Image, @ContentType, @ImageDescription, @ImgSize)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@Image", SqlDbType.Binary, iFileLength).Value = FileByteArray;
cmd.Parameters.Add("@ContentType", SqlDbType.VarChar, 50).Value = upFile.ContentType;
cmd.Parameters.Add("@ImageDescription", SqlDbType.VarChar, 200).Value = txtDesc.Text;
cmd.Parameters.Add("@ImgSize", SqlDbType.BigInt, 8).Value = upFile.ContentLength;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
bigbear_lj 2003-08-19
  • 打赏
  • 举报
回复
将本地图像文件读成文件流,插入或更新到sqlserver中的image字段中以二进制形式存储。从数据库中读该字段,输出文件流,存成临时文件,有picture控件显示就可以。
lihonggen0 2003-08-19
  • 打赏
  • 举报
回复
http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158
Knight94 2003-08-19
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topicview.asp?id=1690497
soulroom 2003-08-19
  • 打赏
  • 举报
回复
OleDbConnection Conn = new OleDbConnection();
OleDbCommand Cmd = Conn.CreateCommand();
Cmd.CommandText = "Insert Into t_Goods_Image(Goods_ID, Goods_Image) Values (?, ?)";
OleDbParameter ParamID = Cmd.Parameters.Add(new OleDbParameter("Goods_ID", System.Data.OleDb.OleDbType.VarWChar, 50, "Goods_ID"));
OleDbParameter ParamImage = Cmd.Parameters.Add(new OleDbParameter("Goods_Image", System.Data.OleDb.OleDbType.VarBinary, 0, "Goods_Image"));
ParamID.Value = GoodsID.ToString();

try
{
FileStream ImageStream = File.OpenRead(lblPicPath.Text);
byte[] bytStream = new byte[ImageStream.Length];
long lngRead = ImageStream.Length;
lngRead = ImageStream.Read(bytStream, 0, (int)lngRead);
ParamImage.Value = bytStream;
}
catch(FileNotFoundException Ex)
{
MessageBox.Show("未找到指定图像文件!");
Console.Write(Ex.Message);
}
catch(FileLoadException Ex)
{
MessageBox.Show("无法读取图像文件!");
Console.Write(Ex.Message);
}

DBConnection.OpenConnection(Conn);
long lngAffected = Cmd.ExecuteNonQuery();
Conn.Close();

110,524

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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