How to use SqlParameter with Update Query

N

None

Hi,

I have to update my table using SqlParameter. Below is my code for
update.

cmdText = "update docs set Content = @content where DirName='" +
DirName.Replace("'","''") + "' and LeafName='Hidden.txt'"
SqlCommand cmd = new SqlCommand();
cmd.CommandText = cmdText;
cmd.Connection = con;
SqlParameter objParam = new SqlParameter("@content", SqlDbType.Image,
binFile.Length);
objParam.Direction = ParameterDirection.Input;
objParam.Value = binFile;
cmd.Parameters.Add(objParam);
int i = cmd.ExecuteNonQuery()

when i execute this code it's returing i valu -1.(No records affected).
What is the problem in my code. If anbody knows please let me know to
solve it.


Thanks,
Vinoth

(e-mail address removed)
 
M

Morten Wennevik

Hi Vinoth,

Try using SqlParameters for all parameters.

"UPDATE docs SET Content = @content WHERE DirName = @dirname AND LeafName = @leafname"

This makes it much easier to debug.
You might also want to check out the ado.net newsgroup

microsoft.public.dotnet.framework.adonet
 

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