给个向orcale数据库插入图片的例子 向orcale数据库插入图片,table已经定义为CREATE TABLE PIC(ID VARCHAR2(20),RRM82_PICTURE BLOB ) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个与Sql Server中没有什么大的区别吧。在插入命令中使用参数,图片转换为二进制流(byte []),赋给参数,执行插入命令。 http://pengyeer.javaeye.com/blog/183107 图片转换为二进制方法。。其他和SQL基本类似。如果实在些不出来。上网上找个列子。。应该有。 //选择图片OpenFileDialog myfile = new OpenFileDialog(); myfile.Filter = "JPG图片|*.jpg|BMP图片|*.bmp|GIF图片|*.gif"; myfile.Multiselect = false; if (myfile.ShowDialog() == DialogResult.OK) {//路径 string imgpath = myfile.FileName; string IMGNAME = imgpath.Substring(imgpath.LastIndexOf("\\") + 1, (imgpath.LastIndexOf(".") - imgpath.LastIndexOf("\\") - 1)); string IMGTYPE = imgpath.Substring(imgpath.LastIndexOf(".") + 1); Bitmap bitmap = new Bitmap(myfile.OpenFile()); //上传的同时显示图片 buttonEdit_图片.Text = IMGNAME; this.pictureBox1.Image = bitmap; Bitmap image = new Bitmap(bitmap); MemoryStream memStream = new MemoryStream(); image.Save(memStream, System.Drawing.Imaging.ImageFormat.Jpeg); bytes = memStream.ToArray(); memStream.Close(); }//保存图片 if (bytes != null) { string sql = "update Photo set **=:BlobData where **='" + textBox1.Text.ToString().Trim() + "'"; boperate.savecom(sql,bytes); }//读取显示图片 OracleDataReader dr = boperate.getread("SELECT Photo FROM ** where **='"+Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim()+"'"); while (dr.Read()) { if (dr["Photo"]==DBNull.Value) { Bitmap bitmap = new Bitmap(Application.StartupPath + @"\..\..\Resources\图片\\暂无图片.jpg"); this.pictureBox1.Image = bitmap; } else { MemoryStream ms = new MemoryStream((Byte[])dr["Photo"]); Bitmap images = new Bitmap(ms); this.pictureBox1.Image = images; } }//读取打开图片 OracleDataReader sdr = boperate.getread("SELECT Photo FROM ** where **='" + Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim() + "'"); while (sdr.Read()) { if (sdr["Photo"] == DBNull.Value) { MessageBox.Show("暂无图片"); } else { Byte[] bytes = new Byte[(sdr.GetBytes(0, 0, null, 0, int.MaxValue))]; sdr.GetBytes(0, 0, bytes, 0, bytes.Length); //string filename = Path.GetRandomFileName().ToString();//随机文件名 string filename = Path.GetRandomFileName().ToString();//随机文件名 //FileStream对象将封装的文件的相对路径或绝对路径 //string filePath = @"f:\" +filename.Substring (filename.LastIndexOf(".")+1) + ".doc"; string filePath = 系统.frmMain.address + @"\" + filename.Substring(filename.LastIndexOf(".") + 1) + ".jpg"; FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite); fs.Write(bytes, 0, bytes.Length); fs.Close(); //sdr.Close(); System.Diagnostics.Process.Start(filePath);//打开图片 } } QQ聊天工具开发碰到的几个难题。。。 <C#程序开发范例宝典>电子书下载? 跪求小游戏代码(滑铁卢战役) NHibernate分页问题 C#:如何在picturebox中显示已捕获的视频 我想用asp里面的界面! 将焦点留在目前的窗口? 怎么设置aspx到html的映射????????? datagrid控件(winform)问题 验证控件怎么用呀!!!!(在线) 关于静态方法 (WebForm)關於gridview控件模版的問題<< 新手求助!!!請大大來幫忙!!!>>
OpenFileDialog myfile = new OpenFileDialog();
myfile.Filter = "JPG图片|*.jpg|BMP图片|*.bmp|GIF图片|*.gif";
myfile.Multiselect = false;
if (myfile.ShowDialog() == DialogResult.OK)
{//路径
string imgpath = myfile.FileName;
string IMGNAME = imgpath.Substring(imgpath.LastIndexOf("\\") + 1,
(imgpath.LastIndexOf(".") - imgpath.LastIndexOf("\\") - 1)); string IMGTYPE = imgpath.Substring(imgpath.LastIndexOf(".") + 1);
Bitmap bitmap = new Bitmap(myfile.OpenFile());
//上传的同时显示图片
buttonEdit_图片.Text = IMGNAME;
this.pictureBox1.Image = bitmap; Bitmap image = new Bitmap(bitmap);
MemoryStream memStream = new MemoryStream();
image.Save(memStream, System.Drawing.Imaging.ImageFormat.Jpeg);
bytes = memStream.ToArray();
memStream.Close(); }//保存图片
if (bytes != null)
{
string sql = "update Photo set **=:BlobData where **='" + textBox1.Text.ToString().Trim() + "'";
boperate.savecom(sql,bytes);
}
//读取显示图片
OracleDataReader dr = boperate.getread("SELECT Photo FROM ** where **='"+Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim()+"'");
while (dr.Read())
{
if (dr["Photo"]==DBNull.Value)
{
Bitmap bitmap = new Bitmap(Application.StartupPath + @"\..\..\Resources\图片\\暂无图片.jpg");
this.pictureBox1.Image = bitmap;
}
else
{
MemoryStream ms = new MemoryStream((Byte[])dr["Photo"]);
Bitmap images = new Bitmap(ms);
this.pictureBox1.Image = images;
}
}
//读取打开图片
OracleDataReader sdr = boperate.getread("SELECT Photo FROM ** where **='" + Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim() + "'");
while (sdr.Read())
{ if (sdr["Photo"] == DBNull.Value)
{
MessageBox.Show("暂无图片");
}
else
{
Byte[] bytes = new Byte[(sdr.GetBytes(0, 0, null, 0, int.MaxValue))];
sdr.GetBytes(0, 0, bytes, 0, bytes.Length);
//string filename = Path.GetRandomFileName().ToString();//随机文件名
string filename = Path.GetRandomFileName().ToString();//随机文件名
//FileStream对象将封装的文件的相对路径或绝对路径
//string filePath = @"f:\" +filename.Substring (filename.LastIndexOf(".")+1) + ".doc";
string filePath = 系统.frmMain.address + @"\" + filename.Substring(filename.LastIndexOf(".") + 1) + ".jpg";
FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
//sdr.Close();
System.Diagnostics.Process.Start(filePath);//打开图片
}
}