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

Home Posts Topics Members FAQ

SqlCommand send '' instead of ' to stored procedure

You may want to do this, since the first single quote is missing in your
e-mail:

string sqlCounty = "'";

For (int i=0, i<cblCounties.Items.Count)

{

sqlCounty += cblCounties.Items[i].Value.Trim() + "', '";

}

sqlCounty = sqlCounty.Substring(0,sqlCounty.Length - 3);

I don't know what your stored procedure is, but you may also consider adding
the "(" and ")" here instead of in the stored procedrue:

e.g. Field in @sqlCounty

Indstesd of: Field in (@sqlCounty)

Then the first line would be:

string sqlCounty = "('";

and you would have to add a line at the end:

sqlCounty += ")";

Bill - wi************@aaipharma.com

Nov 17 '05 #1
1 1577
Let's tidy up Bill's a bit:

StringBuilder sbCounty = new StringBuilder("'", 200); // 200 for
starting capacity chosen mostly at random
foreach(ListITem li in cblCounties.Items)
{
sbCounty.Append(li.Value.Trim());
sbCounty.Append("','");
}

sbCounty.Length -=3; // Just set the length of the StringBuilder, and it
will trim it.

You could use a for/next loop as well, I just think the foreach look
neater. It also only evalueates cblCounties.Items once, instead of twice
per iteration. The difference is probably negligible here, but for some
control collections (like RichTextBox.Lines), it's not.

Also, I don't think that adding the "(" ")" to the parameter will
work -- because they're not part of the parameter, they're part of the SQL
syntax.
--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"Bill Struve" <Bi********@nospam.nospam> wrote in message
news:ux**************@TK2MSFTNGP10.phx.gbl...
You may want to do this, since the first single quote is missing in your
e-mail:

string sqlCounty = "'";

For (int i=0, i<cblCounties.Items.Count)

{

sqlCounty += cblCounties.Items[i].Value.Trim() + "', '";

}

sqlCounty = sqlCounty.Substring(0,sqlCounty.Length - 3);

I don't know what your stored procedure is, but you may also consider adding the "(" and ")" here instead of in the stored procedrue:

e.g. Field in @sqlCounty

Indstesd of: Field in (@sqlCounty)

Then the first line would be:

string sqlCounty = "('";

and you would have to add a line at the end:

sqlCounty += ")";

Bill - wi************@aaipharma.com

Nov 17 '05 #2

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

Similar topics

1
by: ivan divandelen | last post by:
Hi, How can i pass a parameter SQL stored Procedure from ASP pages
1
by: joao dias | last post by:
hi all, sorry this is a bit lenghty... I am getting stucked with an unexpected behaviour of visual studio when I insert an sqlcommand data control in a aspx page, and after configuring it to run...
2
by: Dinesh | last post by:
Hi, I have one stored procedure in SQL server in which i have written one insert statement. Now in my cs file i pass the parameters require to execute that stored procedure and finaly by mistaken...
0
by: Connie Felt | last post by:
I have a c# program that I am building a string that will be passed to SQL as a parameter. The parameter will be used in an IN clause in the procedure. I am building the string like this: ...
2
by: Tracey | last post by:
Sorry for the repeated post. I tried to update a record in database using SqlCommand.ExecuteNonQuery( ) method (I failed using SqlDataAdapter). I traced the above statement and found that it returned...
2
by: vooose | last post by:
Consider executing a stored procedure which has a single INT arg: SqlCommand command = new SqlCommand("Some_Stored_Procedure", conn); command.CommandType =...
4
by: Mr Not So Know It All | last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL Server stored procedure with an input parameter and output parameter CREATE PROCEDURE . @in_rc varchar(8) @out_eList...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
2
by: shahnawaz shaikh | last post by:
hi friends i want to send email thoruth stored procedure or i want to give functionality like alert which is send email automaticaly from database. just like a news or any ad email weekly or...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
1
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: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.