Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sqlCmd.CommandText = "DECLARE @t Table(ContactId int, ROWRANK int" + declare
- + ")INSERT INTO @t(ContactId, ROWRANK" + insertFields + ")"//Insert as few cols a possible
- + "Select ContactID, ROW_NUMBER() OVER (ORDER BY " + sortExpression + " "
- + sortDirection + ") as ROWRANK" // generates a rowrank for each row
- + outerFields
- + " FROM ( SELECT c.id AS ContactID"
- + coreFields
- + from // sometimes different tables are required
- + where + ") T " // user input goes here.
- + groupBy+ " "
- + havingClause //can be empty
- + ";"
- + "select @@rowcount as rCount;" // return 2 recordsets, avoids second query
- + " SELECT " + fields + ",field1,field2" // join onto the other cols n the table
- +" FROM @t t INNER JOIN contacts c on t.ContactID = c.id"
- +" WHERE ROWRANK BETWEEN " + ((pageIndex * pageSize) + 1) + " AND "
- + ( (pageIndex + 1) * pageSize); // here I select the pages I want
- //Add Parameter to SQL Command
- AddParamToSQLCmd(sqlCmd, "@p" + z.ToString(), SqlDbType.VarChar, 50, ParameterDirection.Input, qc.FieldValue);
- // Create SQL code Fragment
- where.AppendFormat(" {0} {1} {2} @p{3}", qc.BooleanOperator, qc.FieldName, qc.ComparisonOperator, z);
- string query= "SELECT {0} FROM .... WHERE {1}"
- StringBuilder selectclause = new StringBuilder();
- StringBuilder wherecaluse = new StringBuilder();
- // .... the logic here will vary greatly depending on what your system looks like
- MySqlcommand.CommandText = String.Format(query, selectclause.ToString(), whereclause.ToString());
- List<Expression> expressions = new List<Expression>(userConditions.Count);
- foreach(Condition c in userConditions)
- {
- expressions.Add(Expression.Eq(c.Field, c.Value));
- }
- SomeTable[] records = SomeTable.Find(expressions);
- where...
- and (@MyParam5 is null or @MyParam5 = Col5)
Add Comment
Please, Sign In to add comment