c# - Linq Data Source WhereParameters with "\" in value -
asp.net/c# project utilizing linq sql have listbox, values database, used filter linq data source. works fine until have value in listbox contain "\". eg "domain\group name". appreciated!
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"; } }
this parameters like:
linqdatasource1.whereparameters[0] {applicationgroup} convertemptystringtonull: true dbtype: int16 defaultvalue: "domain\\group-name" direction: input name: "applicationgroup" size: 0 type: empty
and error reported
{"input string not in correct format."} [system.formatexception]: {"input string not in correct format."} data: {system.collections.listdictionaryinternal} helplink: null hresult: -2146233033 innerexception: null message: "input string not in correct format." source: "mscorlib" stacktrace: " @ system.number.stringtonumber(string str, numberstyles options, numberbuffer& number, numberformatinfo info, boolean parsedecimal)\r\n @ system.number.parseint32(string s, numberstyles style, numberformatinfo info)\r\n @ system.int16.parse(string s, numberstyles style, numberformatinfo info)\r\n @ system.string.system.iconvertible.toint16(iformatprovider provider)\r\n @ system.convert.changetype(object value, typecode typecode, iformatprovider provider)\r\n @ system.web.ui.webcontrols.parameter.getvalue(object value, string defaultvalue, typecode type, boolean convertemptystringtonull, boolean ignorenullabletypechanges)\r\n @ system.web.ui.webcontrols.parameter.getvalue(object value, string defaultvalue, dbtype dbtype, boolean convertemptystringtonull, boolean ignorenullabletypechanges)\r\n @ system.web.ui.webcontrols.parameter.getvalue(object value, boolean ignorenullabletypechanges)\r\n @ system.web.ui.webcontrols.parameter.get_parametervalue()\r\n @ system.we b.ui.webcontrols.parametercollection.getvalues(httpcontext context, control control)\r\n @ system.web.ui.webcontrols.queryabledatasourceview.createquerycontext(datasourceselectarguments arguments)\r\n @ system.web.ui.webcontrols.linqdatasourceview.executeselect(datasourceselectarguments arguments)\r\n @ system.web.ui.datasourceview.select(datasourceselectarguments arguments, datasourceviewselectcallback callback)\r\n @ system.web.ui.webcontrols.databoundcontrol.performselect()\r\n @ system.web.ui.webcontrols.basedataboundcontrol.databind()\r\n @ system.web.ui.webcontrols.gridview.databind()\r\n @ 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)}
this not going fly:
dbtype: int16 defaultvalue: "domain\\group-name"
consider changing dbtype 1 of nvarchar
types.
Comments
Post a Comment