borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (VS .Net 2005 and SQL Server RS 2000)Next Topic (Problem with Forms) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Save Query "Image" problem
Poster Message
dicky19
Level: Trainee

Registered: 01-07-2005
Posts: 2

icon Save Query "Image" problem

hi there i have an image i want to save it in access database i want to save the image not the path im using this
Dim tr AsNew ZieZoDB
Dim conn As OleDbConnection
conn = Me.OleDbConnection1
Dim fs As FileStream = New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim s AsString = Me.txtimagepath.Text
'Read the output in binary reader
Dim r As BinaryReader = New BinaryReader(fs)
'Declare a byte array to save the content of the file to be saved
Dim FileByteArray(fs.Length - 1) AsByte
r.Read(FileByteArray, 0, CInt(fs.Length))


and here is the problem in this query


Try

Dim dbclass AsNew ZieZoDB

Dim query AsString

query = "INSERT INTO [StudentInfo] ([StudentID], [StudentImage], [StudentCardNumber] , [StudentName]) VALUES
('" & Me.txtstudentid.Text&"' ,,(??),'" & Me.txtcardnmber.Text & "', '" & Me.txtname.Text & "');"
dbclass.executeNonQuery(query)

what should i put for the image in the query to save thanks




____________________________
wissam

25-09-2005 at 01:04 PM
View Profile Send Email to User Show All Posts | Quote Reply
TJ_01
Level: VB Lord


Registered: 24-08-2005
Posts: 320
icon Re: Save Query "Image" problem

Would this code helps?

FieldName                      Type
Pic OLE                       Object
FileSize                       Text

The following code establishes a database connection and inserts a file in the "Pic" field.

Save the file as SaveImage.vb

Imports System
Imports System.IO
Imports System.Data

Public Class SaveImage
  Shared Sub main()
  'Delaclare 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 an 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





____________________________
Im JAMES  

03-10-2005 at 03:27 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : Save Query "Image" problem
Previous Topic (VS .Net 2005 and SQL Server RS 2000)Next Topic (Problem with Forms) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder