如何仅使用vb.net中的路径在数据库中检索/插入图像 [英] How to retrive/Insert image in database using only path in vb.net
本文介绍了如何仅使用vb.net中的路径在数据库中检索/插入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨..
我想在数据库中存储/检索图像路径而不是数据库中的整个图像。
谢谢
解决方案
使用getImage将文件路径作为字符串并存储到表中的路径
从中获取文件路径您的表格为字符串,然后使用ShowImage显示您的图像
功能 getImagePath()作为 字符串
Dim dlg 作为 新 OpenFileDialog()
Dim StrPath 作为 字符串 =
dlg.Filter = Jpeg文件| * .jpg |所有文件| *。*
如果 dlg.ShowDialog()= Windows.Forms.DialogResult.OK 那么
StrPath = dlg.FileName.ToString
结束 如果
< span class =code-keyword>返回 StrPath
结束 功能
Sub ShowImage(strPath As 字符串)
如果 System.IO.File.Exists(strPath)那么
Dim Img As 图片
Img = 新位图(Bitmap.FromFile(strPath))
PictureBox1.Image = Img
结束 如果
结束 Sub< br $> b $ b
---
salam
将其存储在 varchar
表的列与任何其他数据一样。
而不是将整个路径存储在单个VARCHAR列中。尝试将路径存储在一列中,将文件名存储在另一列中。
例如: - 在第1列存储E:\ Pics \
和Pic1.jpg in列2
Hi..
I want to store/retrieve only image path in database not whole image in database.
thank you
解决方案
use getImage to get file path as string and store path to your table
get file path from your table as string, then use ShowImage to show your image
Function getImagePath() As String Dim dlg As New OpenFileDialog() Dim StrPath As String = "" dlg.Filter = "Jpeg Files|*.jpg|All Files|*.*" If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then StrPath = dlg.FileName.ToString End If Return StrPath End Function Sub ShowImage(strPath As String) If System.IO.File.Exists(strPath) Then Dim Img As Image Img = New Bitmap(Bitmap.FromFile(strPath)) PictureBox1.Image = Img End If End Sub
---
salam
Store it in a varchar
column of your table like any other piece of data.
Rather than storing the entire path in a single VARCHAR column. Try and store the path in a column and the file name in another column.
E.g:- Store E:\Pics\ in column1
and Pic1.jpg in column2
这篇关于如何仅使用vb.net中的路径在数据库中检索/插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文