本文整理汇总了C#中System.Result.AddRow方法的典型用法代码示例。如果您正苦于以下问题:C# Result.AddRow方法的具体用法?C# Result.AddRow怎么用?C# Result.AddRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Result
的用法示例。
在下文中一共展示了Result.AddRow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Select
public Result Select(string sql)
{
List<string> fields = new List<string>();
string fieldset = sql.Split(new string[] { "FROM" }, StringSplitOptions.None)[0].Replace("SELECT", "");
string[] sf = fieldset.Split(',');
foreach (string item in sf)
{
string adder = "";
if (item.ToLower().Contains(" as "))
{
adder = item.ToLower().Split(new string[] { " as " }, StringSplitOptions.None)[1].Trim();
}
else
{
adder = item.Trim();
}
if (adder.Contains('.'))
{
adder = adder.Split('.')[1];
}
fields.Add(adder);
}
this.cmd.CommandText = sql;
Result r = new Result(this.cmd.CommandText);
if (this.connection.State != System.Data.ConnectionState.Open) this.connection.Open();
SQLiteDataReader re = this.cmd.ExecuteReader();
while (re.Read())
{
Row row = new Row(re.StepCount);
foreach (string f in fields)
{
row.AddCell(f, re[f].ToString());
}
r.AddRow(row);
}
re.Close();
return r;
}
示例2: getRow
public Result getRow(Joinable j, string[] fields, Condition[] c = null, GroupBy g = null, OrderBy[] o = null, int limit = 0)
{
this.cmd.CommandText = "SELECT " + String.Join(",", fields) + " FROM " + j.GetTableName();
if (c != null)
{
this.cmd.CommandText += " WHERE (";
foreach (Condition item in c)
{
this.cmd.CommandText += item.ToString() + " AND ";
}
this.cmd.CommandText = this.cmd.CommandText.Remove(this.cmd.CommandText.Length - 5);
this.cmd.CommandText += ") ";
}
if (g != null)
{
this.cmd.CommandText += g.ToString();
}
if (o != null)
{
this.cmd.CommandText += " ORDER BY ";
foreach (OrderBy item in o)
{
this.cmd.CommandText += item.ToShortString() + ", ";
}
this.cmd.CommandText = this.cmd.CommandText.Remove(this.cmd.CommandText.Length - 2);
}
if (limit != 0)
{
this.cmd.CommandText += " LIMIT " + limit.ToString();
}
Result r = new Result(this.cmd.CommandText);
if (this.connection.State != System.Data.ConnectionState.Open) this.connection.Open();
SQLiteDataReader re = this.cmd.ExecuteReader();
while (re.Read())
{
Row row = new Row(re.StepCount);
foreach (string f in fields)
{
row.AddCell(f, re[f].ToString());
}
r.AddRow(row);
}
re.Close();
return r;
}
示例3: Join
/// <summary>
/// Get a Join on TWO tables.
/// </summary>
/// <param name="tables"></param>
/// <param name="c"></param>
/// <param name="g"></param>
/// <param name="o"></param>
/// <returns></returns>
public Result Join(Joinable[] tables, Condition[] c, GroupBy g, OrderBy[] o)
{
string sql = "SELECT ";
List<string> fields = new List<string>();
foreach (Joinable j in tables)
{
sql += String.Join(",", j.GetFields(true)) + ", ";
foreach (string item in j.GetFields(true))
{
fields.Add(item);
}
}
sql = sql.Remove(sql.Length - 2);
sql += " FROM ";
foreach (Joinable j in tables)
{
sql += j.GetTableName() + ", ";
}
sql = sql.Remove(sql.Length - 2);
sql += " WHERE (";
sql += tables[0].GetJoinOn(tables[1]) + "=" + tables[1].GetJoinOn(tables[0]); //TODO: make this work for more tables...
sql += ") ";
if (c != null)
{
sql += " AND (";
foreach (Condition item in c)
{
sql += item.ToString() + " AND ";
}
sql = sql.Remove(sql.Length - 5);
sql += ") ";
}
if (g != null)
{
sql += g.ToString();
}
if (o != null)
{
sql += " ORDER BY ";
foreach (OrderBy item in o)
{
sql += item.ToShortString() + ", ";
}
sql = sql.Remove(sql.Length - 2);
}
this.cmd.CommandText = sql;
Result r = new Result(this.cmd.CommandText);
if (this.connection.State != System.Data.ConnectionState.Open) this.connection.Open();
SQLiteDataReader re = this.cmd.ExecuteReader();
while (re.Read())
{
Row row = new Row(re.StepCount);
foreach (string f in fields)
{
row.AddCell(f, re[f].ToString());
}
r.AddRow(row);
}
re.Close();
return r;
}