1、使用blob将保存为二进制格式,(可以用浏览器来转换)随后用base64编码来保存,再将base64编码保存进数据库的clob类型字段上。
2、然后要用一个数据名称SystemDataOracleClient。
3、创建一个储存文件,然后把相关代码写入比如string execSql="insert into clob_table(clob_id,) values(1,:clob_pic);"编写代码的时候注意,后缀的符号(;")也要写入,不然无法进行下一步指令。
4、之前上面用的是base64编码,当显示的时候要将输出到浏览器流中,不然在base64里面是看不到。
5、在输出的时候要把转换成二进制(buffur即二进制编码)。
6、随后上传即可,然二进制流也可以存成文件(File)存到FTP服务器,当需要的时候可以根据路径进行下载的。
Public Sub Combo1_Click()
Dim adoCnn As ADODBConnection
Dim rstOra As ADODBRecordset
Dim intI As Integer
Set adoCnn = New ADODBConnection
Set rstOra = New ADODBRecordset
adoCnnConnectionString = "Provider=OraOLEDBOracle;User ID=dzjc;password=zlkj;Data Source=dzjc_2005;" '读blob字段要用Provider=OraOLEDBOracle
adoCnnCursorLocation = adUseClient
adoCnnOpen
rstOraCursorLocation = adUseClient
rstOraActiveConnection = adoCnn
rstOraOpen "SELECT zp FROM dzjcdzjc_wfzp WHERE xh = '5'"
'Set Image1DataSource = rstOra
Set Image1Picture = PictureFromByteStream(rstOraFields("zp")Value)
End Sub
1将以二进制存入数据库
//保存到数据库
protected void Button1_Click(object sender, EventArgs e)
{
//路径
string strPath = "~/photo/03JPG";
string strPhotoPath = ServerMapPath(strPath);
//读取
FileStream fs = new SystemIOFileStream(strPhotoPath, FileModeOpen, FileAccessRead);
BinaryReader br = new BinaryReader(fs);
byte[] photo = brReadBytes((int)fsLength);
brClose();
fsClose();
//存入
SqlConnection myConn = new SqlConnection("Data Source=127001;Initial Catalog=TestDB;User ID=sa;Password=sa");
string strComm = " INSERT INTO personPhoto(personName, personPhotoPath, personPhoto) ";
strComm += " VALUES('wangwu', '" + strPath + "', @photoBinary )";
SqlCommand myComm = new SqlCommand(strComm, myConn);
myCommParametersAdd("@photoBinary", SqlDbTypeBinary,photoLength);
myCommParameters["@photoBinary"]Value = photo;
myConnOpen();
myCommExecuteNonQuery();
myConnClose();
}
2读取二进制在页面显示
//读取
SqlConnection myConn = new SqlConnection("Data Source=127001;Initial Catalog=TestDB;User ID=sa;Password=sa");
string strComm = " SELECT personPhoto FROM personPhoto WHERE personName='wangwu' ";
SqlCommand myComm = new SqlCommand(strComm, myConn);
myConnOpen();
SqlDataReader dr = myCommExecuteReader();
while (drRead())
{
byte[] photo = (byte[])dr["personPhoto"];
thisResponseBinaryWrite(photo);
}
drClose();
myConnClose();
或
SqlConnection myConn = new SqlConnection("Data Source=127001;Initial Catalog=TestDB;User ID=sa;Password=sa");
SqlDataAdapter myda = new SqlDataAdapter(" SELECT personPhoto FROM personPhoto WHERE personName='11' ", myConn);
DataSet myds = new DataSet();
myConnOpen();
mydaFill(myds);
myConnClose();
byte[] photo = (byte[])mydsTables[0]Rows[0]["personPhoto"];
thisResponseBinaryWrite(photo);
3设置Image控件显示从数据库中读出的二进制
---------------------------------------------
SqlConnection myConn = new SqlConnection("Data Source=19216801;Initial Catalog=TestDB;User ID=sa;Password=sa");
SqlDataAdapter myda = new SqlDataAdapter(" SELECT personPhoto FROM personPhoto WHERE personName='11' ", myConn);
DataSet myds = new DataSet();
myConnOpen();
mydaFill(myds);
myConnClose();
byte[] photo = (byte[])mydsTables[0]Rows[0]["personPhoto"];
//路径
string strPath = "~/photo/wangwuJPG";
string strPhotoPath = ServerMapPath(strPath);
//保存文件
BinaryWriter bw = new BinaryWriter(FileOpen(strPhotoPath,FileModeOpenOrCreate));
bwWrite(photo);
bwClose();
3显示
thisImage1ImageUrl = strPath;
4GridView中ImageField以URL方式显示
--------------------------
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="personName" HeaderText="姓名" />
<asp:ImageField DataImageUrlField="personPhotoPath"
HeaderText="">
</asp:ImageField>
</Columns>
</asp:GridView>
5GridView显示读出的二进制
//样板列
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="personName" HeaderText="姓名" />
<asp:ImageField DataImageUrlField="personPhotoPath"
HeaderText="">
</asp:ImageField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (eRowRowIndex < 0)
return;
// SystemComponentModelContainer
string strPersonName = (string)DataBinderEval(eRowDataItem, "personName");
Image tmp_Image = (Image)eRowCells[2]FindControl("Image1");
if (!SystemConvertIsDBNull(DataBinderEval(eRowDataItem, "personPhoto")))
{
//
byte[] photo = (byte[])DataBinderEval(eRowDataItem, "personPhoto");
//路径
string strPath = "~/photo/" + strPersonNameTrim() + "JPG";
string strPhotoPath = ServerMapPath(strPath);
//保存文件
BinaryWriter bw = new BinaryWriter(FileOpen(strPhotoPath, FileModeOpenOrCreate));
bwWrite(photo);
bwClose();
//显示
tmp_ImageImageUrl = strPath;
}
}
不需要原,实际上你可以把它理解成文件流。所以说你只需要读取到数据库的二进制到然后解析还原成原就可以了。像你这种情况应该是还原的方法不对或者是二进制有问题。
这是我的一段你参照下看可以不:
byte[] MyData = new byte[0];
if (MyData != null && !RowGetString("CstSignature")IsNullOrEmpty())
{
MyData = (byte[])Row["CstSignature"];//读取第一个的位流
int ArraySize = MyDataGetUpperBound(0);//获得数据库中存储的位流数组的维度上限,用作读取流的上限
FileStream fs = new FileStream(@"c:/00jpg", FileModeOpenOrCreate, FileAccessWrite);
fsWrite(MyData, 0, ArraySize);
fsClose(); //-- 写入到c:/00jpg。
(thisFindControl("picPhoto") as StarPictureBox)Image = ImageFromFile("c:/00jpg");
}
以上就是关于图片如何存放在oracle数据库全部的内容,包括:图片如何存放在oracle数据库、vb.net如何读取oracle数据库中的图片、Sqlserver数据库存储的图片格式(二进制数据)怎么显示到页面等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)