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

首頁 > 編程 > .NET > 正文

VB.NET 操作 ACCESS OLE 字段內容

2024-07-10 13:05:04
字體:
來源:轉載
供稿:網友

數據庫結構:
--------------------------------------
test.mdb [放在bin目錄下]
表 test(id 自動編號, img ole)
----------------------------------------------

代碼:
----------------------------------------------------
使用 一個 openfiledialog ,兩個 picturebox

----------------------------------------------------------------------
imports system.io
public class form1
inherits system.windows.forms.form

dim cnn as data.oledb.oledbconnection

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 openfiledialog1.showdialog = dialogresult.ok then
picturebox1.image = image.fromfile(openfiledialog1.filename)
end if
end sub

private sub dbinit()
try
cnn = new data.oledb.oledbconnection("provider=microsoft.jet.oledb.4.0;data source=" & application.startuppath & "/test.mdb")
cnn.open()
catch exp as oledb.oledbexception
msgbox(exp.message)
end
end try
end sub

private sub dbrelease()
cnn.close()
cnn = nothing
end sub

private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click
if picturebox1.image is nothing then
msgbox("請先選擇圖片", msgboxstyle.exclamation)
exit sub
end if
dim fs as filestream = new filestream(openfiledialog1.filename, filemode.open, fileaccess.read)
dim bt(fs.length) as byte
fs.read(bt, 0, fs.length)
fs.close()
fs = nothing
dim olecmd as oledb.oledbcommand = new oledb.oledbcommand
dbinit()
olecmd.connection = cnn
olecmd.commandtype = commandtype.text
olecmd.commandtext = "insert into test (img) values (@img)"
olecmd.parameters.add("@img", oledb.oledbtype.binary).value = bt
olecmd.executenonquery()
olecmd = nothing
dbrelease()
msgbox("圖片插入成功")
end sub

private sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.click
dim olecmd as oledb.oledbcommand = new oledb.oledbcommand("select img from test where id=1")
olecmd.commandtype = commandtype.text
dbinit()
olecmd.connection = cnn
dim dr as oledb.oledbdatareader = olecmd.executereader(commandbehavior.singlerow)
if dr.read then
if not isdbnull(dr.item(0)) then
dim bt() as byte = dr.item(0)
dim ms as memorystream = new memorystream(bt)
picturebox2.image = image.fromstream(ms)
else
msgbox("無圖片")
end if
else
msgbox("無數據")
end if
dr.close()
dr = nothing
olecmd = nothing
dbrelease()
end sub
end class

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 柞水县| 冕宁县| 嘉峪关市| 聂拉木县| 宁津县| 乌兰浩特市| 滦南县| 九龙坡区| 西乌珠穆沁旗| 磐石市| 蒙山县| 新宾| 蓝田县| 三台县| 东乌珠穆沁旗| 伊川县| 襄樊市| 抚松县| 崇礼县| 华阴市| 新绛县| 高州市| 安庆市| 集安市| 翼城县| 长春市| 环江| 天峻县| 凤翔县| 江陵县| 阳春市| 甘洛县| 任丘市| 麻江县| 绥中县| 永德县| 彩票| 怀柔区| 铁岭县| 玛纳斯县| 侯马市|