Adding Parameters dynamically for search string from string array

I am building a search string dynamically. One of the items for the string is stored in a sting array in a ViewState object. I want to be able to retrieve the values from the ViewState object and create the string. I have part of the code here and need help in completing the portion indicated. Main problem is how do I build the string for the parameter values. Thanks in advance.

OracleCommand cmd = conn.create(); 

if
( ViewState ["stringArray"]!=null )

{

String [] stringArray=ViewState ["stringArray"];if ( stringArray.Length>0 )

{

if ( stringArray.Length==1 )

{

sb.Append( "AND COLUMN_NAME=:COULUMN_NAME" );

sb.Append( " " );

cmd.Parameters.Add( "COLUMN_NAME", OracleType.VarChar, 10 ).Value=stringArray[0].toString();

else // HELP NEEDED for the else portion ( AND COLUMN_NAME IN ( value1, value2...)

{

sb.Append( "
AND COLUMN_NAME IN ("+" ";for ( int i=0; i<stringArray.Length; i++ )

{

if ( i<stringArray.Length-1 )

{

str=str+
"'"+stringArray [i]+"'"+",";

}

else

{

str=str+
"'"+stringArray [i]+"'"+")"+" ";

} //end of else

}// end of for

 

} //end of else

} //end of if

}


If this answered your question, be sure to mark it as the answer.
0
ks2007
2/29/2008 4:29:42 PM
asp.net.oracle 2269 articles. 0 followers. Follow

5 Replies
607 Views

Similar Articles

[PageSpeed] 9

sb.Append ("'" + String.Join("','", stringArray) + "'"); // Constructs 'ab','cd','ef' from an array with {"ab", "cd", "ef"}

Hope this helps?


Mark replies as answers if they helped you solve the problem.
0
siva_sm
2/29/2008 4:56:22 PM

Looks ok to me except that when setting your stringArray you should cast it to a string array as follows:

string[] stringArray = (string[])ViewState["stringArray"];

Does this work? If not post the error you get. 

0
markarmitage
2/29/2008 4:57:03 PM
I have have figured out what to do and the code works correctly. I will post the code if anyone is interested.
If this answered your question, be sure to mark it as the answer.
0
ks2007
3/1/2008 1:05:21 AM

Go on then, I'd like to know what the answer was. 

0
markarmitage
3/1/2008 2:26:17 PM

Mark,

Here's the complete code. The bold portion  was the one that I was looking for  help as indicated in my question .

if ( ViewState ["stringArray"]!=null )

{

String [] stringArray=(string[]) ViewState ["stringArray"];if ( stringArray.Length>0 )

{

if ( stringArray.Length==1 )

{

sb.Append( "AND COLUMN_NAME=:COLUM_NAME" );sb.Append( " " );

 

cmd.Parameters.Add(
"COLUMN_NAME", OracleType.VarChar, 6 ).Value=stringArray [0];

}

else

{

sb.Append(
"AND COLUMN_NAME IN ("+" ");for ( int i=0; i<stringArray.Length; i++ )

{

if ( i<stringArray.Length-1 )

{

sb.Append(":COLUMN_NAME" + i + ",");

m_Value = stringArray [i];

cmd.Parameters.Add(
"COLUMN_NAME" + i , OracleType.VarChar, 6 ).Value=stringArray [i];

}

else

{

sb.Append(
":COLUMN_NAME" +i + ")" + " ");sb.Append( " " );

cmd.Parameters.Add( "COLUMN_NAME" +i , OracleType.VarChar, 6 ).Value=stringArray [i];

} //end of else

}// end of for

} //end of else

} //end of if

}

 

 


If this answered your question, be sure to mark it as the answer.
0
ks2007
3/3/2008 1:58:08 PM
Reply:

Similar Artilces:

Creating dynamic array,adding stringsinto the array and retrieving string
hi, I want to create a dynamic array which will contain string......then dynamically I will add strings to the array....At the end how i will retrieve strings from that array...... for example....i have a textbox, a button named add, and a button named show...... 1st i will write some string in the textbox....whene i click on the ADD button.the string wriiten in the textbox will be added to the array.....again i will write another string in textbox...again click the ADD button....that will be added to the array................. so at the end when i click on the SHOW button, I want to see ...

Displaying Search String Results in GridView using String Array
I created a .aspx page with a search function to look for records in the database based on the keyword the user inputs into the textbox and then display the results in a gridview when the user clicks the submit button.  As of right now I have setup an SQLDataSource on the page that runs the following query:SELECT * FROM [recipe] WHERE ([keyword] LIKE '%' + @keyword + '%') I also setup an event handler for the Button1_Click event to set the SQLDataSource I created as the DataSource for the GridView and then did a Databind();protected void Button1_Click(object send...

string() = string()
this code does not work (not instance of object) Dim Items(), Other() As String Items = New String() {"A","B","C"} Other = New String() {} Other = Items how can I get all the values ? angiras Hi, If I understand your requirement correctly, this should do it Dim Items() As String = {"A", "B", "C"} Dim Other(Items.Length - 1) As String Items.CopyTo(Other, 0) To more closely match you code above, but this will be less efficient Dim Items(), Other() As String ...

string and string[]
hello, whats the difference here between string and string[] thanks "string" denotes an item of type String "string[]" denotes an array of type String itemsThanks, EdMicrosoft MVP - ASP/ASP.NET Gracia mon ami...

String and String[]
What will be the advantage of using myString: String[10] over myString: String Man wrote: > What will be the advantage of using > myString: String[10] > over > myString: String "String[10]" is a fixed-length, statically allocated, Ansi-based ShortString. "String" is a dynamic-length, dynamically allocated, reference counted, Ansi-based or Unicode-based (depening on Delphi version) Long string. Unless you absolutely need the static, fixed length nature of ShortString, such as in records that interact with external systems, you should stay ...

String and string?
Hi guys, I was wondering the difference between small letter string type and a capital letter String type. Does anyone know about this? Highly appreciate for your answers! Thankz! The "proper" version is String, as it references the System.String class of the .NET Framework Class Library. The ability to use string is provided by C#, where it is an alias to String. Similarly, the "proper" version of an integer is Int32, as it references System.Int32.  The ability to use int is provided by C#, and the ability to use Integer is provided by VB.NET, and both int and Integer are aliases...

string to string[]
Hi, I've got this code : string[] Params; string SQL = "SELECT * FROM T_MANAGEMENT_PAGES"; SqlCommand myCommand = new SqlCommand(SQL, myConnection); myConnection.Open(); SqlDataReader myReader = myCommand.ExecuteReader(); try { while (myReader.Read()) { Params_Type = myReader.GetValue(0).ToString(); } } catch { } finally { } myReader.Close(); My problem is to obtain Params_Type. But each time, it says : "impossible to convert '[object]' in 'string[]' &quo...

How to create array of strings dynamically in vb.net?
Hi there I need to read the menu items from table and wants to create arrays of menus dynamically. Like dim Expertise() as string = {"ONE", "TWO", "THREE"} ONE, TWO and THREE will be comming from the database. Pls assist me the same for my convenient. Regards Raj_________________________________________________________________________...

Adding string to database, but name of string is added, not data
Hello, I am tring to add a string my database.  Info is added, but it is the name of the string, not the data contained within.  What am I doing wrong?  The text "Company" and "currentUserID" is showing up in my database, but I need the info contained within the string.  All help is appreciated!     Imports System.Data Imports System.Data.Common Imports System.Data.SqlClientPartial Class _DefaultInherits System.Web.UI.Page   Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArg...

Number of Strings in an array of Strings
Hello all, I have the following code: {code} const String Interface[] = {"TCP/IP","UDP/IP","RS232","RS485"}; const String BaudRate[] = {"600","1200","2400","4800","9600","19200","38400","56700"}; .. .. .. Idx = 0; while (Idx++ < (sizeof(Interface)/sizeof(Interface[0]))) cbFAMSInterface->Items->Add(Interface[Idx]); Idx = 0; while (Idx++ < (sizeof(BaudRate)/sizeof(BaudRate[0]))) cbFAMSBaudRate->Items->Add(BaudRate[Idx]); {code} T...

Convert string to string array.
Hi, We have a string array argument in datawindow object for 'IN' sql statement. Our user enter a string in a single line edit. How to convert the string to a string array for the argument of datawindow? ex. user input : 'A', 'B', 'C' => str_arr[]={'A', 'B', 'C'} dw_1.retrieve(str_arr) Thanks in advance. Take a look at the n_cst_string object in the pfc. It has a method called of_ParseToArray that does exactly what you're looking for. It's a pretty simple task to 'port' the code ...

search string in a string in C#
Hello, How would you search XYZ_ in a string and if exist, return next three characters after string (so, if XYZ_001, return 001), otherwise return null in C#. Thanks, Jim. //myText is the string variable string next3 = null; int pos = myText.IndexOf("XYZ_") if (pos >= 0) { //may be pos + 3; I have trouble determining that without testing next3 = myText.Substring(pos + 4, 3); } return next3; I think an error will occur if only two characters remain in the string instead of 3, so you may need to add a try..catch block. BrianBrian&quo...

a string in a string in a string in my code behind....
I know my title talk about code-behind, but this is really a client-side problem (and surely a newby one too, sorry about that).I have a javascript function that my make a little text appear when the onmouseover event of a link is activated.So, normally, if my link was inside my html code, it would be something like this:<a href = "whocare.com"  onmouseover="poplink('I want to test something');">test</a>BUT, for some reason, I have to write this part in code behind with the LiteralControl function....and that will give something like that:this.Controls.Add(new LiteralCo...

m_AVP As IDictionary(Of String, String) = New Dictionary(Of String, String) ,not defined?
   I am creating a usercontrol (ascx,ascx.vb)   I have used Imports system.Collections Imports system.Collections.Generic     Private m_AttributeValuePair As IDictionary(Of String, String) = New Dictionary(Of String, String)     But I am gettting an error “Type Dictionary is not defined”   And also I am getting intelisense to type the line But what is the reason for my error ? How can I get escape from the error ?         this error is not showing today  ...

Web resources about - Adding Parameters dynamically for search string from string array - asp.net.oracle

Placebase team at Apple file “Schematic Maps” patent dynamically detailing important data
In a report from Computerworld way back in 2009, we learned that Apple had quietly acquired Maps API company Placebase. Then, founder of Placebase ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

In a dynamically typed language, is it a bad idea to return different data types?
In some cases, returning different types from a single function works.

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ...

Everything.me launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...


A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97%

Everything.me Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 12/6/2015 7:57:55 PM