I have a page which is throwing Missing operand before 'And' operator error on this code:
string filtre = (Request["pn"] == "Tous" ? "pn=pn" : "pn='" + Request["pn"] + "'");
filtre += (Request["dep"] == "Tous" ? "" : " and erreur=" + Request["dep"]);
filtre += (Request["err"] == "Tous" ? "" : " and reference=" + Request["err"]);
filtre += (Request["comp"] == "Tous" ? "" : " and compagnie='" + Request["comp"] + "'");
filtre += (Request["prob"] == "on" ? " and not reference=58" : "");
StringBuilder tbltxt = new StringBuilder();
foreach (DataRow ligne in Datatbl.Tables["ins"].Select(filtre, (Request["tridep"] == "on" ? "erreur" : "datecr")))
The foreach line is throowing this error.
Even with this error the page gets rendered correctly. It is just annoying to get this error by e-mail even thogh the user did not get an error page.
Can someone help me with this?
Thank you
EDIT:
1- This code generates an Excel sheet
2- Not all computers that loads the page generates this error
3- The Excel we use is Excel 2010
4- It throws this error 3 times every time time the error is generated
Here is the complete error message:
Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
System.Data.SyntaxErrorException: Syntax error: Missing operand before 'And' operator. System.Data.ExpressionParser.Parse() System.Data.DataExpression..ctor(DataTable table, String expression, Type type) System.Data.Select..ctor(DataTable table, String filterExpression, String sort, DataViewRowState recordStates) System.Data.DataTable.Select(String filterExpression, String sort) inspectionrapport.fonctions.Page_Load() in c:\Projets\Intranet\Timesheets\Timesheets\Rapports\insptest\inspectionrapport.aspx.cs:line 45 System.Web.Util.CalliHelper.ArglessFunctionCaller(IntPtr fp, Object o) System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) System.Web.UI.Control.OnLoad(EventArgs e) System.Web.UI.Control.LoadRecursive() System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)