Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Help vb.net uploading photo to db(longblob) datatype

zyokiman

Novice
Advanced Member
Messages
25
Reaction score
0
Points
26
Patulongnaman po mga sir :(


may PictureBox ako, Button for browse file (using Open File Dialong) tsaka Button for Insert to Database..

possible ba na mag insert to using Odbc Command? puro kasi naka stored proc nasa net :(

kung me source code man lng po kayo na mabibigay much appreciated. :praise:


THANKS IN ADVANCE :(

NAKAKABALIW NA :rofl: :upset:

View attachment 296590
 

Attachments

  • Capture.JPG
    Capture.JPG
    16.9 KB · Views: 5
Last edited:
Patulongnaman po mga sir :(


may PictureBox ako, Button for browse file (using Open File Dialong) tsaka Button for Insert to Database..

possible ba na mag insert to using Odbc Command? puro kasi naka stored proc nasa net :(

kung me source code man lng po kayo na mabibigay much appreciated. :praise:


THANKS IN ADVANCE :(

NAKAKABALIW NA :rofl: :upset:

View attachment 1170749

path nlng ng pic ang e save mo sa database boss....

maybe this help....--> http://stackoverflow.com/questions/21250945/save-image-in-database-using-file-path-vb10 and http://ccm.net/faq/29114-visual-basic-net-saving-image-path-to-an-access-database
 
Baka makatulong..Convert mo sa binary ung file then save sa database mo. then pag preview na converto mo to image ulit make sure na tama ung file extention nya.

'Convert image to binary
oDialog.Filter = "Bitmap |*.bmp| JPG | *.jpg | GIF | *.gif | All Files|*.*"
If oDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
'Converting Report to binary
Dim fInfo As New IO.FileInfo(oDialog.FileName)
Dim numByte As Integer = CInt(fInfo.Length)
Dim fStream As New IO.FileStream(oDialog.FileName, IO.FileMode.Open, IO.FileAccess.Read)
Dim bReader As New IO.BinaryReader(fStream)
Dim bData As Byte() = bReader.ReadBytes(numByte)
Dim imgData As Byte() = bData
tmpimgData = imgData

'Convert binary to image
Public Function ImgConvt(ByVal tImg As Byte(), ByVal tExt As String)
Try
sFileName = Nothing
Dim sFolderName As String = "Exported Document"

If System.IO.Directory.Exists(Application.StartupPath & "\" & sFolderName) Then
System.IO.Directory.Delete(Application.StartupPath & "\" & sFolderName, True)
End If
FileIO.FileSystem.CreateDirectory(Application.StartupPath & "\" & sFolderName)
sFileName = Application.StartupPath & "\" & sFolderName & "\" & tExt
If FileIO.FileSystem.FileExists(sFileName) Then
FileIO.FileSystem.DeleteFile(sFileName)
End If
Dim fs As New IO.FileStream(sFileName, IO.FileMode.CreateNew)
fs.Write(tImg, 0, tImg.Length)
fs.Close()
fs.Dispose()
 
try nyo po ito...


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OpenFileDialog1 As New OpenFileDialog

OpenFileDialog1.Filter = "Picture Files (*)|*.bmp;*.gif;*.jpg"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
End Sub
 
-- Imports system.io to use memorystream

dim img as Image
img=Picturebox1.image
dim ms as new MemoryStream()
img.save(ms,img.RawFormat)--Convert it to byte
dim byt as Byte()
byt=ms.Toarray()
dim command as new Mysqlcommand("insert into yourtable (yourblobfeild) values (@image)",yourMysqlConnection)
command.parameters.addwithvalue("@image",byt)
yourMysqlConnection.open()
command.executenonquery()
--your image will be saved as byte array

-- to access the image back to picturebox
dim adapter as new mysqdataadapter("select your imagefieldname from your tablename",your connection)
dim ds as new dataset()
yourconnection.open()
adapter.fill(ds)
yourconnection.close()

dim byt as Byte()=TryCast(ds.tables(0).rows(0).items(0),Byte())
Memorystream ms =new MemoryStream(byt)
Image img=Image.fromStream(ms)
Picturebox1.image=img

Hope this helps
 
salamat sa mga tumulong sir, nakuha ko na sya.. hehhe :))
 
Mas better kung path isave mo hindi mabigat sa database kesa sa blob
 
Back
Top Bottom