Examples

Simple Query

Code:
Dim Q As New QBuilder.SelectQuery

Q.TableName = "test"
Q.Fields.Add("a")
Q.Fields.Add("b")
Q.Fields.Add("c")

Q.AddCriteria(New QBuilder.Criteria("a", Criteria.Operation.EqualTo, "@Param1"))
Q.AddCriteria(New QBuilder.Criteria("b", Criteria.Operation.EqualTo, "Value"))
Q.AddCriteria(New QBuilder.BetweenCriteria("c", "56", "@Param2"))

Dim subquery As New QBuilder.SelectQuery
subquery.TableName = "SubTable"
subquery.Fields.Add("count(*)")
subquery.AddCriteria(New QBuilder.Criteria("Sub1", Criteria.Operation.EqualTo, "15"))

Q.AddCriteria(New QBuilder.Criteria(subquery, Criteria.Operation.EqualTo, "2"))

Console.WriteLine(Q.GetSQLText)
Output:
SELECT a, b, c FROM test WHERE a = @Param1 AND b = 'Value' AND c BETWEEN '56' AND @Param2 AND (SELECT count(*) FROM SubTable WHERE Sub1 = 15) = 2

Joins

(Requires changeset 12250 or later)
Code:
Dim Query As SelectQuery = New SelectQuery()
Query.Fields.Add("Table1.FieldC")
Query.Fields.Add("Table2.FieldD")
Query.TableName = "Table1"
Query.AddCriteria("Table1.FieldE", Operation.EqualTo, "1")
    
Query.AddJoin("Table2", "Table1.FieldA", Operation.EqualTo, "Table2.FieldB")

console.writeline(Query.GetQueryText)
Output:
SELECT Table1.FieldC, Table2.FieldD FROM Table1 INNER JOIN Table2 ON Table1.FieldA = Table2.FieldB WHERE Table1.FieldE = 1

Last edited Oct 17, 2011 at 1:41 AM by BradleyUffner, version 16

Comments

BradleyUffner Apr 22, 2013 at 7:24 PM 
Yes, you may have to download the source code and recompile it with the 3.5 framework though. The source is in VB, but you can mix languages in separate projects withing the same solution.

tasker Apr 8, 2013 at 5:01 PM 
Can I use this in a 3.5 asp.net C# application?