利用 LinQ to SQL 的 ASP.NET/C# 项目我有列表框,其中包含来自数据库的值,用于过滤 Linq 数据源。一切正常,直到我在包含“\”的列表框中有值。例如“域\组名”。任何帮助,将不胜感激!
if (ddlAppGroup.SelectedValue != "*")
{
LinqDataSource1.WhereParameters.Add(new Parameter("ApplicationGroup", System.Data.DbType.Int16));
LinqDataSource1.WhereParameters["ApplicationGroup"].DefaultValue = ddlAppGroup.SelectedValue;
if (LinqDataSource1.Where == "")
{
LinqDataSource1.Where = "ApplicationGroup == @ApplicationGroup";
}
else
{ LinqDataSource1.Where = LinqDataSource1.Where + " && ApplicationGroup == @ApplicationGroup"; }
}
这是参数的样子:
LinqDataSource1.WhereParameters[0]
{ApplicationGroup}
ConvertEmptyStringToNull: true
DbType: Int16
DefaultValue: "DOMAIN\\Group-Name"
Direction: Input
Name: "ApplicationGroup"
Size: 0
Type: Empty
这就是报告的错误
{"Input string was not in a correct format."}
[System.FormatException]: {"Input string was not in a correct format."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
HResult: -2146233033
InnerException: null
Message: "Input string was not in a correct format."
Source: "mscorlib"
StackTrace: " at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)\r\n at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)\r\n at System.Int16.Parse(String s, NumberStyles style, NumberFormatInfo info)\r\n at System.String.System.IConvertible.ToInt16(IFormatProvider provider)\r\n at System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider)\r\n at System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges)\r\n at System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, DbType dbType, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges)\r\n at System.Web.UI.WebControls.Parameter.GetValue(Object value, Boolean ignoreNullableTypeChanges)\r\n at System.Web.UI.WebControls.Parameter.get_ParameterValue()\r\n at System.We
b.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control)\r\n at System.Web.UI.WebControls.QueryableDataSourceView.CreateQueryContext(DataSourceSelectArguments arguments)\r\n at System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)\r\n at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)\r\n at System.Web.UI.WebControls.DataBoundControl.PerformSelect()\r\n at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()\r\n at System.Web.UI.WebControls.GridView.DataBind()\r\n at PYOCEnrollment.Admin.AllRequests.btnApply_Click(Object sender, EventArgs e) in C:\\Projects\\PYOCEnrollment\\PYOCEnrollment\\EUE\\AllRequests.aspx.cs:line 265"
TargetSite: {Void StringToNumber(System.String, System.Globalization.NumberStyles, NumberBuffer ByRef, System.Globalization.NumberFormatInfo, Boolean)}