Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving an image file or .doc file to a sql server database

Status
Not open for further replies.

pink2070

Programmer
Jan 29, 2004
23
US
I am trying to save .pdf files to a sql server database table, and I am having trouble actually getting the file to save to the table, I think it may have something to do with the datatype I am using to update the field.

This is what my stored procedure looks like:
CREATE proc PractProc
(@var1 varchar(50), @var2 varchar(50), @varFile image)
as
insert into tblPract(fName, fLast, fFile) values(@var1, @var2,@varFile)
GO


Here is the code I am using to update the stored procedure from code:

Try
Dim objConn As New SqlConnection("Initial Catalog=DatabaseName; Data Source=ServerName; uid=UserName; password=Password")
objConn.Open()
Dim objCmd As New SqlCommand("PractProc", objConn)
objCmd.CommandType = CommandType.StoredProcedure
objCmd.Parameters.Add("@var2", SqlDbType.VarChar).Value = "Value 2!"
objCmd.Parameters.Add("@var1", SqlDbType.VarChar).Value = "Value 1!"
objCmd.Parameters.Add("@varFile", SqlDbType.Image).Value = myData
objCmd.ExecuteNonQuery()
objConn.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try


Problem and error message:
string or binary data would be truncated the statemnet has been terminated.

This occurs, when the @varFile = mydata parameter is executed.

so this leads me to believe that using image as the datatype is not cutting it, I really dont have a clue to be honest, this is an educated guess. If anyone has any sugguestions please feel free to express them

Thanks,

Pink



 
A PDF file is not an image! If you want to upload the whole thing, I suggest you read it into a byte array and then store it as a BLOB (binary large object) or a large enough byte array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top