-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: kmkrishna1
Message 5 in Discussion

 
Hi, 
Once again Coding Part ..... 
Save the file as SaveImage.vb. <o:p></o:p>Imports SystemImports 
System.IO<o:p></o:p>Imports System.Data<o:p></o:p> <o:p></o:p>Public Class 
SaveImage<o:p></o:p>  Shared Sub main()<o:p></o:p>  'Declare a file stream object 
<o:p></o:p>  Dim o As <o:p></o:p>System.IO.FileStream<o:p></o:p>  'Declare a stream 
reader object<o:p></o:p>  Dim r As <o:p></o:p>StreamReader<o:p></o:p>  Dim jpgFile As 
String<o:p></o:p>  Console.Write("Enter a Valid .JPG file path")<o:p></o:p>  jpgFile = 
Console.ReadLine<o:p></o:p>  If Dir(jpgFile) = "" Then<o:p></o:p>   
Console.Write("Invalid File Path")<o:p></o:p>   Exit Sub<o:p></o:p>  End If<o:p></o:p> 
 'Open the file <o:p></o:p>  o = New FileStream(jpgFile, FileMode.Open, 
<o:p></o:p>FileAccess.Read, FileShare.Read)<o:p></o:p>  'Read the output in a stream 
reader<o:p></o:p>  r = New StreamReader(o)<o:p></o:p>  Try<o:p></o:p>    'Declare a 
byte array to save the content of the file to be<o:p></o:p>saved<o:p></o:p>    Dim 
FileByteArray(o.Length - 1) As Byte<o:p></o:p>    o.Read(FileByteArray, 0, 
o.Length)<o:p></o:p>'Open the database connection. Please map the datasource name to 
match the 'Database path<o:p></o:p>    Dim Con As 
New<o:p></o:p>System.Data.OleDb.OleDbConnection("Provider=Microsoft.JetOLEDB.3.51;Persist<o:p></o:p>Security
 Info=False;Data Source=DbImages.mdb")<o:p></o:p>    Dim Sql As String = "INSERT INTO 
DbImages (Pic,FileSize) VALUES (?,?)"<o:p></o:p>    'Declare a OleDbCommand Object 
<o:p></o:p>    Dim CmdObj As New System.Data.OleDb.OleDbCommand(Sql, Con)<o:p></o:p>   
 'Add the parameters<o:p></o:p>    CmdObj.Parameters.Add("@Pic", 
System.Data.OleDb.OleDbType.Binary,<o:p></o:p>o.Length).Value = 
FileByteArray<o:p></o:p>   CmdObj.Parameters.Add("@FileSize", 
System.Data.OleDb.OleDbType.VarChar,<o:p></o:p>100).Value = o.Length<o:p></o:p>  
Con.Open()<o:p></o:p>  CmdObj.ExecuteNonQuery()<o:p></o:p>  Con.Close()<o:p></o:p>  
Catch ex As Exception<o:p></o:p>    Console.Write(ex.ToString)<o:p></o:p>  End 
Try<o:p></o:p> End Sub<o:p></o:p> 
End Class

-----------------------------------------------------------

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]

Reply via email to