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
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