PC Review


Reply
Thread Tools Rate Thread

Blob: INSERT a file in SQL Server

 
 
Michael Maes
Guest
Posts: n/a
 
      11th Jul 2003
Hello,

I'm trying to INSERT all kind of files in a SQL Server 2000 Table.
These files are e-mail attachments (.PDF, .XLS, .DOC, ....).

Using the code below, returns an IConvertible error.
The DataType of the field is 'Text'. Should this be 'Image'?

What am I missing?

Michael

Dim sqlCONN As New SqlConnection(global.sdc)

Dim scmd As New SqlCommand("UPDATE tblEmailAttachments SET
attachment=@attachment WHERE emailID = " & emailID & " AND fileName = " &
fileName, sqlCONN)

Dim fs As New System.IO.FileStream(SourceFilePath, IO.FileMode.Open,
IO.FileAccess.Read)

Dim b(fs.Length() - 1) As Byte

fs.Read(b, 0, b.Length)

fs.Close()

Dim P As New SqlParameter("@attachment", SqlDbType.Text, b.Length,
ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, b)

scmd.Parameters.Add(P)

sqlCONN.Open()

scmd.ExecuteNonQuery()

sqlCONN.Close()



 
Reply With Quote
 
 
 
 
Steven Bras [MS]
Guest
Posts: n/a
 
      11th Jul 2003
One of these two articles should get you going:

317034 HOW TO: Read and Write a File to and from a BLOB Column by Using
http://support.microsoft.com/?id=317034

and/or

317034 HOW TO: Read and Write a File to and from a BLOB Column by Using
http://support.microsoft.com/?id=317034

Hope this helps!

Steven Bras, MCSD
Microsoft Developer Support/Visual Basic WebData

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert 3 Gb binary file to oracle blob using Ado.net oracleclient kapatel@sfwmd.gov Microsoft ADO .NET 1 8th Aug 2006 10:04 AM
BLOB Insert Briaaan@gmail.com Microsoft VB .NET 1 11th Feb 2006 09:23 AM
Insert BLOB problem =?Utf-8?B?Q2hyaXM=?= Microsoft ADO .NET 1 26th Nov 2005 05:31 PM
Insert BLOB value. Marius Gheorghe Microsoft ADO .NET 11 13th Jul 2005 07:17 PM
Trouble trying to insert Excel file as BLOB into SQL2000 database =?Utf-8?B?QW5kcmUgUmFuaWVyaQ==?= Microsoft ADO .NET 4 17th Jun 2004 07:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:06 AM.