:-D:laugh::laugh::laugh::-D Nothing is impossible!
onlytech
Posts
-
web config -
Search boxOK , back to square one... Try this and see:
Regex isNumb=new Regex("[^0-9]"); string sqlStr= "Select * FROM DRUG_INFORMATION WHERE DrugName = '" + StrUserSearchValue + "'"; if (isNumb.IsMatch(StrUserSearchValue) ==false) sqlStr+= " or DrugNo =" + StrUserSearchValue; OleDbCommand cmd = new OleDbCommand(sqlStr, conn); reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
You will have to include the following statement at top:using System.Text.RegularExpressions;
Well, what we are doing here is to first find whether the search string is a Number or text. If number, then only we should include the "DrugNo = ?" criteria in the where clause of SQL query. hth -geo Nothing is impossible! -
how to show result by pressing Enter Key in a textboxIf you have only one button in your form, then that button is automatically assumed as default (submit type). So no need for tweaking around with EVENTTARGET hiddenfield. If you have more than one buttons, then Stockers' advice works fine for overriding the default behaviour. However I feel your problem here is not the texbox but the combobox. Hitting Enter key from textbox will work with above two methods. But hitting Enter when focus is on combobox, does not trigger the button. Try using some javascript for this purpose: First insert a dummy LinkButton in your form (this will include the hooker function __doPostBack into you HTML code). You can keep the text property of Link button as nothing. Thus the link button will not be visible on the page. Now add this script to your section.
function processKeyEvent(){ if(window.event.keyCode==13) __doPostBack('Button2',''); }
Note that in the abv snippet, you are programatically calling the postback feature of ASP.NET __doPostBack('Button2',''); tells the browser to postback the page assuming that Button2 was clicked. Finally, in the onkeypress event of tag, add this:onkeypress="return processKeyEvent();"
hth -geo Nothing is impossible! -
Search boxWell thats quite obvious. A text cannot be compared with a db field of number datatype. There are a number of ways to tackle this problem: 1. You must change your page UI such that search text or number is entered into separate textboxes and on buttonclick, depending on which textbox is filled, it shud call different queries; the one for DrugNo or DrugName. 2. Keep only one textbox and add a combobox with two values; "Search by Drug No." , "Dearch by Drug Name" Now on buttonclick, depending on the selected value of combobox, call the appropriate query. 3. The simplest approach and also the most expensive in performance: just change the datatype of DrugNo in db to text. And then your query should look like:
"Select * FROM DRUG_INFORMATION WHERE DrugNo ='" + StrUserSearchValue + "' OR DrugName = '" + StrUserSearchValue + "'";
hth -geo Nothing is impossible! -
Search boxThe SQL query is incorrectly framed, try this:
OleDbCommand cmd = new OleDbCommand("Select * FROM DRUG_INFORMATION WHERE DrugNo.DRUG_INFORMATION =" + StrUserSearchValue + " OR DrugName.DRUG_INFORMATION = " + StrUserSearchValue, conn);
or rather I doubt that your query is correct at all! From the select query it presume that the table name is DRUG_INFORMATION. In that case column names should be qualified as DRUG_INFORMATION.DrugNo and DRUG_INFORMATION.DrugName So I feel that above line should perhaps look like this:OleDbCommand cmd = new OleDbCommand("Select * FROM DRUG_INFORMATION WHERE DRUG_INFORMATION.DrugNo =" + StrUserSearchValue + " OR DRUG_INFORMATION.DrugName = '" + StrUserSearchValue + "'", conn);
assuming DrugName is a text column and DrugNo is a number in the access database. If all works well, then I have a suggestion to make: Any kind of search page requires that the code is kept optimized right from the beginning. Read some articles on code/data optimization before you get into the habit of what I call "Horrible Programming". Cheers! -geo Nothing is impossible!