嘿嘿...让你们看看我优美地生成sql
程序代码:
namespace SqlSentence
{
public static class SqlString
{
public static string SELECT(this string select, params string[] columnName)
{
string s=" SELECT ";
for (int i = 0; i < columnName.Length; i++)
{
s += columnName[i] + ",";
}
return select + s.Substring(0, s.Length - 1);
}
public static string FROM(this string from, string tableName)
{
return from + " FROM " + tableName;
}
public static string AS(this string _as, string target)
{
return _as + " AS " + target;
}
public static string WHERE(this string where, string term)
{
return where + " WHERE " + term;
}
public static string EQUAL(this string equal, string value)
{
return equal + " = " + value;
}
public static string AND(this string and, string where)
{
return and + " AND " + where;
}
}
}
using System;
using System.Windows.Forms;
using System.Data.SqlClient;
using SqlSentence;
//using System.Collections.Generic;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
= ("姓名", "姓别".AS("Sex") , "身份证").FROM ("客户").WHERE("姓名".EQUAL("'张三'").AND("姓别".EQUAL("'男'")));
}
}
}
[[it] 本帖最后由 ioriliao 于 2008-8-29 14:58 编辑 [/it]]









