Yukon said:
I've created a very simple asp.net web form (via visual studio 2008) that
has a text box and a submit button. I want to be able to paste a bunch of
'words' into the textbox and have the words used in a select statement.
Something like
SELECT name, address, status
FROM StatsInfo
WHERE status IN (textbox-word1, textbox-word2, textbox-word3,...)
I've got something simple working where a single word can be queried, but I
can't find a way to parse the contents of the textbox so the query searches
for each word. Do you have or know of any examples you could share that
would clue me into how to do this?
The textbox has a text property -- textbox.text. Textbox.text is 'string'.
You pass the Textbox.text list of words into a method.
private void SeperateWordsInString(string instring)
{
}
You then use a string.split. Something has to be a delimiter in the
instring of words like a 'space' character. But something has to be the
delimiter to separate the words.
Then you use the code in the link.
http://msdn.microsoft.com/en-us/library/ms228388(VS.80).aspx
You're going to have to go into some kind of foreach loop with each
iteration selecting a word out of the array.
The for each itteration, you're going to build part of the T-SQL Select
statement based word in the array for the Where.
In other words, you're going to dynamically build the select statement.
string strsql = "Select fld1, fld2 From table Where ("
then its this
foreach(string word in words)
{
strsql = strsql + word + ","
}
At the end, you complete the statement.
strsql = strsql + ")"
You may have to do an IndexOfLast(",") to strip out the last ",".
By building the T-SQL statement programmically that's how you do it.
You can put the code at the stop of you're method at the top of your
code tp call execute against MySQL.
This is just an example. But what if a "'" is part of the word. What are
you going to do to deal with it, because you're for sure get a syntax
error with the Select? I also thought 'sometext' had to have quotes
around the text.
This is VB and the Replace statment and the Replace is used in C# .net too.
sql01 = "UPDATE EquipmentTbl SET "
sql01 = sql01 & "SerialNumber = '" & request.form(strSerialNum) & "', "
sql01 = sql01 & "Description = '" & request.form(strDesc) & "', "
sql01 = sql01 & "Location = '" & request.form(strLoc) & "', "
sql01 = sql01 & Replace(request.form(strLoc),"'","''") & "', "