473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to use SqlParameter with Update Query

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

vi****@gsdindia.com

Nov 17 '05 #1
1 2376
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
On Wed, 03 Aug 2005 07:58:57 +0200, None <vi********@gmail.com> wrote:
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

vi****@gsdindia.com


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: None | last post by:
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...
0
by: None | last post by:
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...
4
by: Jason Huang | last post by:
Hi, I want to use the Sqlparameter and SqlDataAdapter to update my data, and the data will be updated based on two TextBoxes txtCustName and txtCustAddress. Thanks for help. Jason
5
by: Jason Huang | last post by:
Hi, The SqlParameter myPM =new SqlParameter("@Address", txtAddress.Text) is working for update, but SqlParameter myPM =new SqlParameter ("@Address",SqlDbType.NVarChar,90,txtAddress.Text) is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.