Updating SQL db (SqlDbType.Image)

B

Bjørn Nornes

Reading file from disk (jpg)

Dim fi As New FileInfo(workFolder + CStr(mmgcid) + ".jpg")
Dim fs As FileStream = fi.OpenRead()
Dim nBytes As Integer = fi.Length
Dim ByteArray(nBytes) As Byte
Dim nBytesRead As Integer = fs.Read(ByteArray, 0, nBytes)
Dim WebServices As mediaService.Service1 = New mediaService.Service1
Dim retstatus As String

Using WEB service to update SQL database

retstatus = WebServices.UpdateThumbFileBlob(mmgcid, ByteArray)


public string UpdateThumbFileBlob(int MediaID, byte[] mmfbBlobThumb)
{
SqlConnection Connection = new
SqlConnection("SERVER=localhost;DATABASE=db1;UID=user;PWD=pwd");
String updateCmd = "UPDATE MultiMediaFileBlobs SET mmfbBlobThumb
=@mmfbBlobThumb where mmfbId=" + MediaID;
SqlCommand myCommand = new SqlCommand(updateCmd, Connection);
SqlParameter StatusParameter = new SqlParameter("@mmfbBlobThumb",
SqlDbType.Image);
StatusParameter.Value = mmfbBlobThumb;
myCommand.Parameters.Add(StatusParameter);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
}

However record is not updated ?

Anyone who sees any problems with my code here ?

regards
BN
 
M

Manasvin

Can you check whether there are any records getting affected ?

The MediaID concatenation may be creating a problem. Can check your return
value given by myCommand.ExecuteNonQuery() and see if it is more than zero ?
you might inturn return it from the webservice method to keep a permanent
check on the updation

Manasvin
 
C

Cor

Hi Bjorn,

I did look and see not direct something strange.

But there is one problem in your code, in your vb.function you ask for a
return but you do not give it in your webservice.

Why do you not set the execute.nonquery(or everything) in a try catch block
and return the exception if there is one and a blank if there is no
exception?


Cor
 
B

Bjørn Nornes

return value is 0.

However the same procedure (webService) works grets on other data, eg.
string, int etc.

..... and I found the problem, which you mentioned was the MediaID value sent
to
the WebService function.....


thanks for your help....

regards
BN


Can you check whether there are any records getting affected ?

The MediaID concatenation may be creating a problem. Can check your return
value given by myCommand.ExecuteNonQuery() and see if it is more than zero ?
you might inturn return it from the webservice method to keep a permanent
check on the updation

Manasvin

Bjørn Nornes said:
Reading file from disk (jpg)

Dim fi As New FileInfo(workFolder + CStr(mmgcid) + ".jpg")
Dim fs As FileStream = fi.OpenRead()
Dim nBytes As Integer = fi.Length
Dim ByteArray(nBytes) As Byte
Dim nBytesRead As Integer = fs.Read(ByteArray, 0, nBytes)
Dim WebServices As mediaService.Service1 = New mediaService.Service1
Dim retstatus As String

Using WEB service to update SQL database

retstatus = WebServices.UpdateThumbFileBlob(mmgcid, ByteArray)


public string UpdateThumbFileBlob(int MediaID, byte[] mmfbBlobThumb)
{
SqlConnection Connection = new
SqlConnection("SERVER=localhost;DATABASE=db1;UID=user;PWD=pwd");
String updateCmd = "UPDATE MultiMediaFileBlobs SET mmfbBlobThumb
=@mmfbBlobThumb where mmfbId=" + MediaID;
SqlCommand myCommand = new SqlCommand(updateCmd, Connection);
SqlParameter StatusParameter = new SqlParameter("@mmfbBlobThumb",
SqlDbType.Image);
StatusParameter.Value = mmfbBlobThumb;
myCommand.Parameters.Add(StatusParameter);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
}

However record is not updated ?

Anyone who sees any problems with my code here ?

regards
BN
 

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