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

vinoth@gsdindia.com

Re: How to use SqlParameter with Update Query by Miha

Miha
Wed Aug 03 03:23:09 CDT 2005

Hi,

Perhaps your where condition is wrong?
Btw, you should use a parameter in where condition, too.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"None" <vinkumrect@gmail.com> wrote in message
news:1123048616.736665.323840@g44g2000cwa.googlegroups.com...
> 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
>
> vinoth@gsdindia.com
>