Hi
Any one can help me with storing Graphics Image on to Sql Server. I have some success at easy bit.
When I try to use store procedure then it failed, just get
"System Error".
The table, PHOTOTEST consists of these fields,
pId int INDICATOR (auto number)
photodesc nvarchar(50)
photo image
The store procedure
CREATE PROCEDURE up_InsertPhoto(@photoclip_IM image, @photodesc_V nvarchar(50) )
AS
INSERT INTO phototest
( photodesc,photo )
VALUES ( @photodesc_V,@photoclip_IM )
[u]The code is in
VB.NET</u>
Dim cnnstr As String
Dim filePath As String
Dim cmd As String
Dim fsBLOB As FileStream
Dim svr As SqlDataAdapter
Dim svrConn As SqlConnection
Dim svrParams As SqlParameter
cnnstr = "data source=myserver;user id=myself;password=mypwd;initial catalog=Photos"
filePath = "D:\Photos\MyCar.jpg"
cmd = "up_InsertPhoto"
'reading the JPEG file
fsBLOB = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim oBytes(fsBLOB.Length) As Byte
fsBLOB.Read(oBytes, 0, oBytes.Length)
fsBLOB.Close()
'connecting to server
svrConn = New SqlConnection(cnnstr)
svr = New SqlDataAdapter(cmd, svrConn)
'set 1st param
svrParams = New SqlParameter("@photoclip_IM", SqlDbType.VarBinary)
svrParams.Size = oBytes.Length
svrParams.Value = oBytes
svr.SelectCommand.Parameters.Add(svrParams)
'set 2nd param
svrParams = New SqlParameter("@photodesc_V", SqlDbType.NVarChar)
svrParams.Value = "My car photo"
svr.SelectCommand.Parameters.Add(svrParams)
'open server connection & execute query
svrConn.Open()
svr.SelectCommand.ExecuteNonQuery()
You may notice using SqlDbType.VarBinary for SQL Server Image data type, well if I replace the stored procedure with a string SQL command,
cmd = "INSERT INTO phototest (photodesc,photo) VALUES (@photodesc,@photo)"
Then replacing the parameter names repect to the above command... well it works. I had a look at the MSDN KB article 317701 that why I used to BLOB and SQL DBtype VarBinary,
http://support.microsoft.com/default...b;en-us;317701
I gather that error must caused at the store procedure...but why and what reason, can any one get it to work?
Hope you can help me, thanks in advance.
Kasie.