数据库oracle9i
blob字段
最好有一些代码
完整示例更好
11 个解决方案
#1
C#&Oracle存储和读取图片
http://lp008211.itpub.net/post/25347/227829
http://lp008211.itpub.net/post/25347/227829
#2
是不是把记录转换成图片??
#3
把记录中的图片字段显示出来!!
用一楼即可!!
用一楼即可!!
#4
//图像数据转变byte
MemoryStream ms = new MemoryStream();
this.picDrawData.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
myData = new Byte[ms.Length];
ms.Position = 0;
ms.Read(myData, 0, Convert.ToInt32(ms.Length));
m_DW["DrawData"] = myData;
//显示图像数据
if (!m_DW.IsNull("DrawData"))
{
myData = new byte[0];
myData = (byte[])m_DW["DrawData"];
int bmpSize = new int();
bmpSize = myData.Length;
MemoryStream ms = new MemoryStream();
ms.Write(myData, 0, bmpSize);
Bitmap bmp;
bmp = new Bitmap(ms);
picDrawData.Image = bmp;
ms.Close();
}
private void BuildCommand(IDbDataAdapter iDbDataAdapter)
{
OracleDataAdapter daOracle = (OracleDataAdapter)iDbDataAdapter;
OracleCommandBuilder cbOracle = new OracleCommandBuilder();
cbOracle.DataAdapter = daOracle;
daOracle.InsertCommand = cbOracle.GetInsertCommand();
daOracle.UpdateCommand = cbOracle.GetUpdateCommand();
daOracle.DeleteCommand = cbOracle.GetDeleteCommand();
return;
}
public int DoUpdate(DataTable dataTable, string srcTable)
{
switch (m_DbKind)
{
case DbKinds.Oracle:
OracleConnection cnnOracle = new OracleConnection(m_ConnectionString);
OracleCommand cmdOracle = new OracleCommand("SELECT * FROM " + srcTable, cnnOracle);
OracleDataAdapter daOracle = new OracleDataAdapter(cmdOracle);
BuildCommand(daOracle);
return daOracle.Update(dataTable);
default:
throw (new Exception("无法处理的数据库类型"));
}
Access acc = new Access();
//SQL保证取得的数据是一条
DataTable dt = acc.GetDBTable("表名",SQL);
DataRow dr = dt.Rows[0];//注意这里是修改,如果是新增的话应该是dt.NewRow()
dr["DrawData"] = frm.DrawData;//赋值
int i = acc.DoUpdate(dt.GetChanges(), "表名");
#5
用DataGridView的SelectionChanged触发鼠标点击事件,然后this.DataGridView1["pictureID", this.DataGridView1.CurrentRow.Index].Value得到pictureID的值,再通过pictureID对数据库进行检索得到路径就可以了
#6
把你的数据读出来(读到字节数组中)
主要代码如下:
主要代码如下:
MemoryStream buf=new MemoryStream((byte[])reader[0]); //reader是datareader
Image image=Image.FromStream(buf,true);
pictureBox1.Image=image;
#7
1楼和4楼的代码都没注释```
而且变量也没声明
看起来也忒费劲了``````
而且变量也没声明
看起来也忒费劲了``````
#10
看我发的简单.也是主要代码.呵呵.
#11
祝福楼主了。
#1
C#&Oracle存储和读取图片
http://lp008211.itpub.net/post/25347/227829
http://lp008211.itpub.net/post/25347/227829
#2
是不是把记录转换成图片??
#3
把记录中的图片字段显示出来!!
用一楼即可!!
用一楼即可!!
#4
//图像数据转变byte
MemoryStream ms = new MemoryStream();
this.picDrawData.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
myData = new Byte[ms.Length];
ms.Position = 0;
ms.Read(myData, 0, Convert.ToInt32(ms.Length));
m_DW["DrawData"] = myData;
//显示图像数据
if (!m_DW.IsNull("DrawData"))
{
myData = new byte[0];
myData = (byte[])m_DW["DrawData"];
int bmpSize = new int();
bmpSize = myData.Length;
MemoryStream ms = new MemoryStream();
ms.Write(myData, 0, bmpSize);
Bitmap bmp;
bmp = new Bitmap(ms);
picDrawData.Image = bmp;
ms.Close();
}
private void BuildCommand(IDbDataAdapter iDbDataAdapter)
{
OracleDataAdapter daOracle = (OracleDataAdapter)iDbDataAdapter;
OracleCommandBuilder cbOracle = new OracleCommandBuilder();
cbOracle.DataAdapter = daOracle;
daOracle.InsertCommand = cbOracle.GetInsertCommand();
daOracle.UpdateCommand = cbOracle.GetUpdateCommand();
daOracle.DeleteCommand = cbOracle.GetDeleteCommand();
return;
}
public int DoUpdate(DataTable dataTable, string srcTable)
{
switch (m_DbKind)
{
case DbKinds.Oracle:
OracleConnection cnnOracle = new OracleConnection(m_ConnectionString);
OracleCommand cmdOracle = new OracleCommand("SELECT * FROM " + srcTable, cnnOracle);
OracleDataAdapter daOracle = new OracleDataAdapter(cmdOracle);
BuildCommand(daOracle);
return daOracle.Update(dataTable);
default:
throw (new Exception("无法处理的数据库类型"));
}
Access acc = new Access();
//SQL保证取得的数据是一条
DataTable dt = acc.GetDBTable("表名",SQL);
DataRow dr = dt.Rows[0];//注意这里是修改,如果是新增的话应该是dt.NewRow()
dr["DrawData"] = frm.DrawData;//赋值
int i = acc.DoUpdate(dt.GetChanges(), "表名");
#5
用DataGridView的SelectionChanged触发鼠标点击事件,然后this.DataGridView1["pictureID", this.DataGridView1.CurrentRow.Index].Value得到pictureID的值,再通过pictureID对数据库进行检索得到路径就可以了
#6
把你的数据读出来(读到字节数组中)
主要代码如下:
主要代码如下:
MemoryStream buf=new MemoryStream((byte[])reader[0]); //reader是datareader
Image image=Image.FromStream(buf,true);
pictureBox1.Image=image;
#7
1楼和4楼的代码都没注释```
而且变量也没声明
看起来也忒费劲了``````
而且变量也没声明
看起来也忒费劲了``````
#8
#9
#10
看我发的简单.也是主要代码.呵呵.
#11
祝福楼主了。