国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > .NET > 正文

VB.NET操作 SQL SERVER的 二進(jìn)制數(shù)據(jù)

2024-07-10 13:00:59
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
在vb時(shí)期, 向sql server 中插入二進(jìn)制數(shù)據(jù), 是通過(guò) adodb.stream 實(shí)現(xiàn), 在.net中, 對(duì) “流”格式的操作更加強(qiáng)大而簡(jiǎn)單,本篇演示向sql server 中插入數(shù)據(jù)并讀出的功能.






在窗體上添加一個(gè) openfiledialog 控件, 兩個(gè)picturebox, 代碼如下:
--------------------------------------------------------------------------------------------
imports system.io
public class form1
inherits system.windows.forms.form

private sub button4_click(byval sender as system.object, byval e as system.eventargs) handles button4.click
me.dispose(true)
end sub

private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
if ofdpic.showdialog = dialogresult.ok then
pbpreview.image = image.fromfile(ofdpic.filename)
end if
end sub

private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click
if pbpreview.image is nothing then
msgbox("請(qǐng)先選擇圖片", msgboxstyle.exclamation)
exit sub
end if
dim fs as filestream = new filestream(ofdpic.filename, filemode.open, fileaccess.read)
dim bt(fs.length) as byte
fs.read(bt, 0, fs.length)
fs.close()
fs = nothing
dim sqlconn as sqlclient.sqlconnection = new sqlclient.sqlconnection("server=(local);user id=sa;password=123;database=pubs")
sqlconn.open()
dim sqlcmd as new sqlclient.sqlcommand("sp_insertimage", sqlconn)
sqlcmd.commandtype = commandtype.storedprocedure
sqlcmd.parameters.add("@img", sqldbtype.image).value = bt
sqlcmd.executenonquery()
sqlcmd = nothing
sqlconn.close()
sqlconn = nothing
msgbox("圖片插入成功", msgboxstyle.information)
end sub

private sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.click
dim sqlconn as sqlclient.sqlconnection = new sqlclient.sqlconnection("server=(local);user id=sa;password=123;database=pubs")
sqlconn.open()
dim sqlcmd as new sqlclient.sqlcommand("select img from test where t_id=3", sqlconn)
sqlcmd.commandtype = commandtype.text

dim bt() as byte = sqlcmd.executescalar()
if not bt is nothing then
if bt.length > 0 then
dim fs as memorystream = new memorystream(bt)
pbreview.image = image.fromstream(fs)
'fs.close
'fs = nothing
'可以自己試著將上面兩句的注釋去掉, 看有什么效果 ^_^
else
msgbox("無(wú)圖片")
end if
else
msgbox("無(wú)數(shù)據(jù)")
end if

sqlcmd = nothing
sqlconn.close()
sqlconn = nothing
end sub
end class
-----------------------------------------------------------------------------
數(shù)據(jù)庫(kù)部分:
----------------
use pubs
go
create table test(t_id int identity(1,1), img image)
go
create procedure sp_insertimage
@img image
as
insert into test (img) values (@img)
go





發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 肥城市| 肥东县| 边坝县| 纳雍县| 平舆县| 重庆市| 溧阳市| 平南县| 顺昌县| 高碑店市| 万年县| 城口县| 黎平县| 金塔县| 石棉县| 信宜市| 蓝山县| 个旧市| 巢湖市| 庐江县| 宝兴县| 怀宁县| 连山| 方城县| 玛多县| 丰都县| 宁远县| 庆安县| 芜湖市| 镇江市| 黄山市| 嘉定区| 滦南县| 读书| 贡觉县| 鄂尔多斯市| 南充市| 个旧市| 修文县| 保靖县| 璧山县|