473,467 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2383
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.