Как найти конкретный идентификатор из моего текстового поля в C#
Уважаемое Сообщество Кода Проекта
I have tried to program in C# using Visual Studio 2015 to search for a specific number from my textbox, but I have been running in circles. In this case, it was QuoteID from my textbox (txtSearch) and display it in my GridView which is bound to (SqlDataSourceQuoteSelection). The dropdown list (ddlQuoteSelection) is used for the user to select what type of search they want (IThe dropdownlist is not databound. The category names were manually added, but the value of the selected item was the exact same name as the db column to be searched, such as QUOTEID). However, my SQL statement was unable to find the specific number entered into the textbox. I am receiving the following error for this code:
Syntax error: Missing operand after ''%,#,%'' operator. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SyntaxErrorException: Syntax error: Missing operand after ''%,#,%'' operator. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [SyntaxErrorException: Syntax error: Missing operand after ''%,#,%'' operator.] System.Data.ExpressionParser.Parse() +2202491 System.Data.DataExpression..ctor(DataTable table, String expression, Type type) +140 System.Data.DataView.set_RowFilter(String value) +148 System.Web.UI.WebControls.FilteredDataSetHelper.CreateFilteredDataView(DataTable table, String sortExpression, String filterExpression, IDictionary filterParameters) +413 System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1889 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +22 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +151 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +76 System.Web.UI.WebControls.GridView.DataBind() +10 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +114 System.Web.UI.WebControls.GridView.OnPreRender(EventArgs e) +26 System.Web.UI.Control.PreRenderRecursiveInternal() +90 System.Web.UI.Control.PreRenderRecursiveInternal() +163 System.Web.UI.Control.PreRenderRecursiveInternal() +163 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +906
Честно говоря, я не знаю, как это решить...Пожалуйста, кто-нибудь может дать мне какой-нибудь совет?
Что я уже пробовал:
Мой текущий код (ошибка выше):
<pre> if (ddlQuoteSelection.SelectedValue == "QUOTEID") { string FilterExpression = string.Concat(ddlQuoteSelection.SelectedValue.ToString(), "LIKE '%,#,%' "); SqlDataSourceQuoteSelection.FilterParameters.Clear(); SqlDataSourceQuoteSelection.FilterParameters.Add(newControlParameter(ddlQuoteSelection.SelectedValue, "txtSearch", "Text")); SqlDataSourceQuoteSelection.FilterExpression = FilterExpression; Response.Write("<script>alert('G Statuses Successfully Found')</script>"); }
Я также попытался заменить"%,#, % " на следующее:
1) [0-9]
2) %,[0-9],%
3) ,[0-9],
4) ,#,
Что сработало:
1) "ddlQuoteSelection.Выбранное значение.ToString()' Исправлена проблема int32, связанная с использованием в качестве строки.