473,322 Members | 1,405 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,322 software developers and data experts.

C# Inserting % into a string

I have the following line:

string SearchValue = string.Format("Select ACCOUNTID,
ACCOUNT from ACCOUNT where ACCOUNT LIKE \'{0:#%}\' order
by ACCOUNT, SearchString.Trim()");

I have tried just about everything to insert a % into my
string. In the past this has not been an issue since I
mostly use stored procedures. I am running some test
queries on a database that I do not want to add new
stored procedures to.

SearchString comes from a text box on my test form.

The above code returns the following error:
Index (zero based) must be greater than or equal to zero
and less than the size of the argument list.

Suggestions greatly appreciated.

Nov 15 '05 #1
7 1805
Hi johnp,

I'm guessing "SearchString.Trim()" was intended to be the second
parameter of the method call, but you included it within the string literal
passed as the first parameter to String.Format.

Regards,
Dan

"johnp" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
I have the following line:

string SearchValue = string.Format("Select ACCOUNTID,
ACCOUNT from ACCOUNT where ACCOUNT LIKE \'{0:#%}\' order
by ACCOUNT, SearchString.Trim()");

I have tried just about everything to insert a % into my
string. In the past this has not been an issue since I
mostly use stored procedures. I am running some test
queries on a database that I do not want to add new
stored procedures to.

SearchString comes from a text box on my test form.

The above code returns the following error:
Index (zero based) must be greater than or equal to zero
and less than the size of the argument list.

Suggestions greatly appreciated.

Nov 15 '05 #2
SearchString was supposed to be the first paramter.

Adjusting the code as follows:

string SearchValue = string.Format("Select ACCOUNTID,
ACCOUNT from ACCOUNT where ACCOUNT LIKE \'{0}{1:#%}\'
order by ACCOUNT, SearchString.Trim()");

Still generates the same error messsage.

Help still needed. I am not sure what the C# archetect
team was thinking when they restricted certain characters
from normal strings... Delphi is more flexible.

-----Original Message-----
Hi johnp,

I'm guessing "SearchString.Trim()" was intended to be the secondparameter of the method call, but you included it within the string literalpassed as the first parameter to String.Format.

Regards,
Dan

"johnp" <an*******@discussions.microsoft.com> wrote in messagenews:01****************************@phx.gbl...
I have the following line:

string SearchValue = string.Format("Select ACCOUNTID,
ACCOUNT from ACCOUNT where ACCOUNT LIKE \'{0:#%}\' order by ACCOUNT, SearchString.Trim()");

I have tried just about everything to insert a % into my string. In the past this has not been an issue since I
mostly use stored procedures. I am running some test
queries on a database that I do not want to add new
stored procedures to.

SearchString comes from a text box on my test form.

The above code returns the following error:
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

Suggestions greatly appreciated.

.

Nov 15 '05 #3
Hello:

Try:

string SearchValue = string.Format("Select ACCOUNTID,
ACCOUNT from ACCOUNT where ACCOUNT LIKE \'{0}{1:#%}\'
order by ACCOUNT", SearchString.Trim());


--
Best regards

Carlos Guzmán Álvarez
Vigo-Spain
Nov 15 '05 #4
Carlos,

I am sorry I guess I had a typo when I pasted that
previous message. There actually was a double quote after
that last ACCOUNT before the comma.

The issue is still here.
Regards,

JohnP
-----Original Message-----
Hello:

Try:

string SearchValue = string.Format("Select ACCOUNTID,
ACCOUNT from ACCOUNT where ACCOUNT LIKE \'{0}{1:#%}\'
order by ACCOUNT", SearchString.Trim());


--
Best regards

Carlos Guzmán Álvarez
Vigo-Spain
.

Nov 15 '05 #5
Carlos,

I am sorry I guess I had a typo when I pasted that
previous message. There actually was a double quote after
that last ACCOUNT before the comma.

The issue is still here.
Regards,

JohnP
-----Original Message-----
Hello:

Try:

string SearchValue = string.Format("Select ACCOUNTID,
ACCOUNT from ACCOUNT where ACCOUNT LIKE \'{0}{1:#%}\'
order by ACCOUNT", SearchString.Trim());


--
Best regards

Carlos Guzmán Álvarez
Vigo-Spain
.

Nov 15 '05 #6
Why not do the following?

string SearchValue = string.Format("Select ACCOUNTID, ACCOUNT from ACCOUNT
where ACCOUNT LIKE \'{0}%\' order by ACCOUNT", SearchString.Trim());

The result I obtain is:

"Select ACCOUNTID, ACCOUNT from ACCOUNT where ACCOUNT LIKE '15%' order by
ACCOUNT"

Tyler

"johnp" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
I have the following line:

string SearchValue = string.Format("Select ACCOUNTID,
ACCOUNT from ACCOUNT where ACCOUNT LIKE \'{0:#%}\' order
by ACCOUNT, SearchString.Trim()");

I have tried just about everything to insert a % into my
string. In the past this has not been an issue since I
mostly use stored procedures. I am running some test
queries on a database that I do not want to add new
stored procedures to.

SearchString comes from a text box on my test form.

The above code returns the following error:
Index (zero based) must be greater than or equal to zero
and less than the size of the argument list.

Suggestions greatly appreciated.

Nov 15 '05 #7
Tyler,

Boy that sure worked. I guess I was mislead by a site
that had an example on how to use % in a string and they
suggested the {0:#%} and since nothing else was working I
went along the wrong path.

Thank you for the assistance everyone!

Regards,

JohnP
-----Original Message-----
Why not do the following?

string SearchValue = string.Format("Select ACCOUNTID, ACCOUNT from ACCOUNTwhere ACCOUNT LIKE \'{0}%\' order by ACCOUNT", SearchString.Trim());
The result I obtain is:

"Select ACCOUNTID, ACCOUNT from ACCOUNT where ACCOUNT LIKE '15%' order byACCOUNT"

Tyler

"johnp" <an*******@discussions.microsoft.com> wrote in messagenews:01****************************@phx.gbl...
I have the following line:

string SearchValue = string.Format("Select ACCOUNTID,
ACCOUNT from ACCOUNT where ACCOUNT LIKE \'{0:#%}\' order by ACCOUNT, SearchString.Trim()");

I have tried just about everything to insert a % into my string. In the past this has not been an issue since I
mostly use stored procedures. I am running some test
queries on a database that I do not want to add new
stored procedures to.

SearchString comes from a text box on my test form.

The above code returns the following error:
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

Suggestions greatly appreciated.

.

Nov 15 '05 #8

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

Similar topics

2
by: altergothen | last post by:
Hi there I am a newbie to ASP.Net - Please Help! I am trying to insert the values of my variables into a database. If I try the following it works perfectly: string insertQuery = "INSERT into...
5
by: hfk0 | last post by:
Hi, I'm new to ASP.net, SQL Server and visual studio.net, and I'm having problem inserting and storing data from a web form to a SQL database. I created a simple ASP.NET web form, a simple SQL...
15
by: Jaraba | last post by:
I am working in a project that I need to parse an arrayt an select records based upon the values parsed. I used the functions developed by Knut Stolze in his article 'Parsing Strings'. I am...
7
by: Andy C Matthews | last post by:
Hi there, I'm building an Access database and using VBA to generate Microsoft Word mailings for customers. It's all going fine so far. However, a variables named ParcelID, a ten-digit string such...
3
by: rcoco | last post by:
Hi, I want to share this problem. I have a datagrid that will help me Insert data into sql database. So I made a button On my form so that when I press the button a new row on datagrid should be...
1
by: madhuxml82 | last post by:
Dear Forum Members, I have generated an XML Schema and a Table of XMLType referencing the XML Schema. Now When I am Inserting the Data into the Table. I am getting the Error 0RA-30937: Error is...
20
by: dav3 | last post by:
Alright folks I am in need of a lil guidance/assistance here. I have a program which reads in a txt file. This txt file contains lines of the form January 3, 2007, 85.8 Now each line of the txt...
0
by: toyin | last post by:
hello, pls help look through this code its not inserting the record in dataset into the another database. i want to insert the row in the dataset into another table in another database. pls help....
0
by: srinivasaraonagisetty | last post by:
hi, I am faceing one problem, while inserting the data in db2 using clob. actually i am writing this type code: public class DBParam { private InputStream inputstream; private static int...
2
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.