-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: kmkrishna1
Message 4 in Discussion
Hi ,
It's fairly easy to save an image in the database using .NET OleDB library. This is
exmple for MS Access DB.The same can be converted in MS SQL or Oracle by changing the
Provider and Parameter.
Save the file as SaveImage.vb. Imports System Imports System.IO Imports System.Data
Public Class SaveImage Shared Sub main() 'Declare a file stream object Dim o As
System.IO.FileStream 'Declare a stream reader object Dim r As StreamReader
Dim jpgFile As String Console.Write("Enter a Valid .JPG file path") jpgFile =
Console.ReadLine If Dir(jpgFile) = "" Then Console.Write("Invalid File Path")
Exit Sub End If 'Open the file o = New FileStream(jpgFile, FileMode.Open,
FileAccess.Read, FileShare.Read) 'Read the output in a stream reader r = New
StreamReader(o) Try 'Declare a byte array to save the content of the file to be
saved Dim FileByteArray(o.Length - 1) As Byte o.Read(FileByteArray, 0,
o.Length) 'Open the database connection. Please map the datasource name to match the
'Database path Dim Con As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.3.51;Persist Security
Info=False;Data Source=DbImages.mdb") Dim Sql As String = "INSERT INTO DbImages
(Pic,FileSize) VALUES (?,?)" 'Declare a OleDbCommand Object Dim CmdObj As New
System.Data.OleDb.OleDbCommand(Sql, Con) 'Add the parameters
CmdObj.Parameters.Add("@Pic", System.Data.OleDb.OleDbType.Binary, o.Length).Value =
FileByteArray CmdObj.Parameters.Add("@FileSize",
System.Data.OleDb.OleDbType.VarChar, 100).Value = o.Length Con.Open()
CmdObj.ExecuteNonQuery() Con.Close() Catch ex As Exception
Console.Write(ex.ToString) End Try End Sub End Class
Visit:
http://searchvb.techtarget.com/vsnetTip/1,293823,sid8_gci918585_tax293037,00.html/
Regards,
K.M.Krishna
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/BDOTNET/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]