Write Multiple Blobs to Single Record

J

Justin Emlay

My following code creates two records. How can I combine this code to not
only write both blobs to a single record but to ALSO write a another normal
string field to the same record (not inserted yet).

Help on either would be greatly appreciated!

Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source='" & Application.StartupPath & "\access.mdb'")
Dim cmdLargeImage As New OleDbCommand("INSERT INTO ImageTable (Image_Data)
VALUES (@LargeImage)", con)
Dim cmdThumbnail As New OleDbCommand("INSERT INTO ImageTable
(Image_ThumbNail) VALUES (@Thumbnail)", con)
cmdLargeImage.CommandType = CommandType.Text
cmdThumbnail.CommandType = CommandType.Text

Dim prmPicLargeImage As New OleDbParameter
prmPicLargeImage.ParameterName = "@LargeImage"
prmPicLargeImage.OleDbType = OleDbType.Binary
prmPicLargeImage.Value = Thumbnail
cmdLargeImage.Parameters.Add(prmPicLargeImage)

Dim prmPicThumbnail As New OleDbParameter
prmPicThumbnail.ParameterName = "@Thumbnail"
prmPicThumbnail.OleDbType = OleDbType.Binary
prmPicThumbnail.Value = Thumbnail
cmdThumbnail.Parameters.Add(prmPicThumbnail)

con.Open()
cmdLargeImage.ExecuteNonQuery()
cmdThumbnail.ExecuteNonQuery()


Thanks again for any help!
 
J

Justin Emlay

nm, I got it.

Dim cmd As New OleDbCommand("INSERT INTO ImageTable (Image_Data,
Image_Thumbnail) VALUES (@LargeImage, @Thumbnail)", con)

&

prmPicImageDescription.OleDbType = OleDbType.Char



Complete code for reference:
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source='" & Application.StartupPath & "\access.mdb'")
Dim cmd As New OleDbCommand("INSERT INTO ImageTable (Image_Data,
Image_Thumbnail, Image_Description) VALUES (@LargeImage, @Thumbnail,
@ImageDescription)", con)
cmd.CommandType = CommandType.Text
Dim prmPicLargeImage As New OleDbParameter
prmPicLargeImage.ParameterName = "@LargeImage"
prmPicLargeImage.OleDbType = OleDbType.Binary
prmPicLargeImage.Value = LargeImage
cmd.Parameters.Add(prmPicLargeImage)
Dim prmPicThumbnail As New OleDbParameter
prmPicThumbnail.ParameterName = "@Thumbnail"
prmPicThumbnail.OleDbType = OleDbType.Binary
prmPicThumbnail.Value = Thumbnail
cmd.Parameters.Add(prmPicThumbnail)
Dim prmPicImageDescription As New OleDbParameter
prmPicImageDescription.ParameterName = "@ImageDescription"
prmPicImageDescription.OleDbType = OleDbType.Char
prmPicImageDescription.Value = "Testing"
cmd.Parameters.Add(prmPicImageDescription)
con.Open()
cmd.ExecuteNonQuery()
con.Close()



If this looks sloppy and anyone cares to clean it up I would love to hear
any suggestions. This is my first time "hard coding" the DB connections. I
will never use the explorer to setup DB's again. What a nightmare!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top