string dir = "";
private string filepath = "";
private string model = "";
protected string data = "abcdefghi";
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 獲取數據
&nbs歡迎光臨學網,收藏本篇文章 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
p; /// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public DataTable GetTable(string sql)
{
DataSet ds = new DataSet();
try
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "initial catalog="+this.tbdata.文章整理:學網 http://www.xue5.com (本站) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
Text.TrimEnd().ToString()+";data source=.;user id="+this.tbuser.Text.TrimEnd()+";passWord="+this.tbpass.Text.TrimEnd();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(ds);
}歡迎光臨學網,點擊這裡查看更多文章教程 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return ds.Tables[0];
}
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = this.GetTable("select * from sysobjects where xtype=''u'' order by status desc");
for (int i = 0; i < dt.Rows.Count文章整理:學網 http://www.xue5.com (本站) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
: #000000">-1; i++)
{
string tableBean = Convert.ToString(dt.Rows[i]["name"]??"").ToUpper();
tableBean = tableBean.Length > 1 ? (tableBean.Substring(0,1).ToUpper()+tableBean.Substring(1).ToLower()) : (tableBean.ToUpper());r /> DataTable dtt = this.GetTable("select * from ["+Convert.ToString(dt.Rows[i]["學網,收藏本篇文章 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
le="COLOR: #000000">name"])+"]");
System.Text.StringBuilder sbshu = new StringBuilder("using System;").Append(System.Environment.NewLine).Append("using System.Collections.Generic;").Append(System.Environment.NewLine).Append("using System.Text;").Append(System.Environment.NewLine).Append("using System.Data;").Append(Environment.NewLine).Append("using System.Data.SqlClIEnt;").Append(System.Environment.NewLine).Append("").Append(System.Environment.NewLine).Append("namespace ").Append(this.tbNamespace.Text.Trim()).Append(System.Environment.NewLine).Append("{學網,收藏本篇文章 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
OR: #000000">").Append(System.Environment.NewLine);
System.Text.StringBuilder sbset = new StringBuilder("");
System.Text.StringBuilder sbbean = new StringBuilder("public " + tableBean + " SelectById(){"+System.Environment.NewLine + tableBean + " " + tableBean.ToLower().ToString() + " = new " +學網,收藏本篇文章 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
R: #000000"> tableBean + "();"+System.Environment.NewLine+"");
sbbean.Append("string sql = "select * from " + tableBean + " where " + dtt.Columns[0].ColumnName.ToString() + "=@" + dtt.Columns[0].ColumnName.ToString()+ "";").Append(Environment.NewLine);
sbbean.Append("SqlParameter[] pas = {new SqlParameter(&q歡迎光臨學網,點擊這裡查看更多文章教程 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
uot;").Append("@").Append(dtt.Columns[0].ColumnName.ToString()).Append(""").Append(",").Append(dtt.Columns[0].ColumnName.ToString()).Append(")};").Append(Environment.NewLine);
sbbean.Append("DataTable dt = db.GetTable(sql,pas);").Append(Environment.NewLine);
sbbean.Append(" if(dt.Rows.Count>0)").Append(Environment.NewLine).Append(" {").Append(Environment.NewLine);
//sql前半部分
StringBuilder歡迎光臨學網,點擊這裡查看更多文章教程 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
sbpas = new StringBuilder("SqlParameter[] pas = {");
StringBuilder sbadd = new StringBuilder("public bool Add()");
sbadd.Append("{");
sbadd.Append(Environment.NewLine);
sbshu.Append(Environment.NewLine);
sbshu.Append("public class ");
sbshu.Append(tableBean);
sbshu.Append("{");
; sbshu.Append(Environment.NewLine);
&nb歡迎光臨學網,點擊這裡查看更多文章教程 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
sp; System.Text.StringBuilder sbsqlbefore = new StringBuilder("insert into ").Append(tableBean).Append("(");
System.Text.StringBuilder sbsqlafter = new StringBuilder(" values(");
StringBuilder sbupd = new StringBuilder("public bool Update()" + Environment.NewLine + "{" + Environment.NewLine + "string sql ="update 文章整理:學網 http://www.xue5.com (本站) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
>").Append(tableBean).Append(" set ");
StringBuilder sbdel = new StringBuilder("public bool Delete()").Append(Environment.NewLine).Append("{").Append("string sql = "delete ").Append(tableBean).Append(" where ").Append("[").Append(dtt.Columns[0].ColumnName.ToString()).Append("]").Append("=").Append("@").Append(dtt.Columns[0].ColumnName.ToString()).Append(學網,收藏本篇文章 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
R: #000000">"";").Append(Environment.NewLine);
StringBuilder sbdelpas = new StringBuilder("SqlParameter[] pas = {");
StringBuilder sbsel = new StringBuilder("public DataTable Select()").Append(Environment.NewLine).Append("{").Append(Environment.NewLine).Append("DataTable dt = db.GetTable("select * from ").Append(tableBean).Append("")??new DataTable();").Append(Environment.NewLine).Append("return dt;").Append(Environment.NewLine).Append("}");
&文章整理:學網 http://www.xue5.com (本站) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
nbsp; //循環字段
for (int j = 0; j < dtt.Columns.Count; j++)
{
sbshu.Append("private string _"+dtt.Columns[j].ColumnName.ToString()+";"+System.Environment.NewLine);
sbset.Append("public string " + dtt.Columns[j].ColumnName.ToString() + "{set{this._" 學網,點擊這裡查看更多文章教程 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
OR: #000000">+ dtt.Columns[j].ColumnName.ToString() + "=value;}get{return this._" + dtt.Columns[j].ColumnName.ToString() + ";}}"+System.Environment.NewLine);
sbbean.Append(" ").Append(tableBean.ToLower().ToString() + "." + dtt.Columns[j].ColumnName.ToString() + "=Convert.ToString(dt.Rows[0]["" + dtt.Columns[j].ColumnName.ToString() + ""]);").Append(System.Environment.NewLine);
歡迎光臨學網,點擊這裡查看更多文章教程 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
; if (j != 0)
{
sbsqlbefore.Append(",");
> sbsqlafter.Append(",");
}
///添加
sbsqlbefore.Append("[").Append(dtt.Columns[j].ColumnName.ToString()).Append("]");
sbsqlafter.Append("@"+學網,點擊這裡查看更多文章教程 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
COLOR: #000000">dtt.Columns[j].ColumnName.ToString());
sbpas.Append("new SqlParameter("");
sbpas.Append("@");
sbpas.Append(dtt.Columns[j].ColumnName.ToString());
sbpas.Append("",");
sbpas.Append(dtt.Columns[j].ColumnName.ToString());
sbpas.Append(")");
if (j < dtt.Columns.Count - 1)
{
&n文章整理:學網 http://www.xue5.com (本站) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
bsp; sbpas.Append(",");
}
///修改
if (j != 0)
{
sbupd.Append("[").Append(dtt.Columns[j].ColumnName.ToString()).Append("]").Append("=");
sbupd.Append("@");
&n歡迎光臨學網,收藏本篇文章 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
bsp; sbupd.Append(dtt.Columns[j].ColumnName.ToString());
if (j < dtt.Columns.Count - 1)
{
sbupd.Append(",");
}
}
}
sbpas.Append("};");
sbsqlbefore.Append(")");
&nbs文章整理:學網 http://www.xue5.com (本站) [1] [2] [3] [4] [5] [6] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
p; sbsqlafter.Append(")");
///循環字段
sbadd.Append("string sql = "").Append(sbsqlbefore.ToString()).Append(sbsqlafter.ToString()).Append(""").Append(";").Append(Environment.NewLine);
sbadd.Append(sbpas.ToString()).Append(Environment.NewLine);
sbadd.Append("return db.GetState(sql,pas);").Append(Environment.NewLine);
sbadd.Append("}").Append(Environment.NewLine);
//添加結束
&n歡迎光臨學網,點擊這裡查看更多文章教程 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
bsp; ///修改
sbupd.Append(" where ");
sbupd.Append(dtt.Columns[0].ColumnName.ToString());
sbupd.Append("=");
sbupd.Append("@");
sbupd.Append(dtt.Columns[0].ColumnName.ToString()).Append("";").Append(Environment.NewLine);
sbupd.Append(sbpas).Append(Environment.NewLine);
sbupd.Append("return db.GetState(sql,pas);").Append(Environment.NewLine);
sbupd.Append(學網,點擊這裡查看更多文章教程 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
>"}").Append(Environment.NewLine);
///刪除
sbdelpas.Append("new SqlParameter("").Append("@").Append(dtt.Columns[0].ColumnName.ToString()).Append(""").Append(",").Append(dtt.Columns[0].ColumnName.ToString()).Append(")};");
sbdel.Append(sbdelpas.ToString()).Append(Environment.NewLine);
sbdel.Append("return db.GetState(sql,pas);").Append(Environment.NewLine).Append("}"文章整理:學網 http://www.xue5.com (本站) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
0">);
//查詢
sbshu.Append(sbset.ToString()).Append(System.Environment.NewLine).Append("DbAccess db = new DbAccess();").Append(Environment.NewLine).Append(sbadd.ToString()).Append(Environment.NewLine).Append(sbupd.ToString()).Append(Environment.NewLine).Append(sbdel.ToString()).Append(Environment.NewLine).Append(sbsel.ToString()).Append(Environment.NewLine).Append("//查詢").Append(System.Environment.NewLine).Append(sbbean.Append(System.Environment.NewLine).Append(" }").Append(Environment.NewLine).Append("return " + tableBean.ToLower().ToString() + ";" + System.Environment.NewLine + "}").ToString());
文章整理:學網 http://www.xue5.com (本站) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
; ///
sbshu.Append(System.Environment.NewLine);
sbshu.Append(System.Environment.NewLine).Append("}").Append(System.Environment.NewLine).Append("}");
this.richTextBox1.Text = sbshu.ToString();
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(this.filepath +"\"+ tableBean + ".cs",false,System.Text.Encoding.GetEncoding(文章整理:學網 http://www.xue5.com (本站) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
000">"gb2312")))
{
sw.Write(sbshu.ToString());
sw.Flush();
}
this.richTextBox1.Text=sbshu.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.folderBrowserDialog1.ShowDialog();
this.filepath=this.folderBrowserDialog1.SelectedPath.ToString();
this.model =文章整理:學網 http://www.xue5.com (本站) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
this.filepath.Substring(this.filepath.LastIndexOf("\")+1);
MessageBox.Show(this.model);
MessageBox.Show(this.filepath);
}
string all = "";
public void ShowAll(string dir)
{
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dir);
if (di.GetFiles().Length > 0)
{
&nbs歡迎光臨學網,點擊這裡查看更多文章教程 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
p; System.IO.FileInfo[] files = di.GetFiles();
for (int i = 0; i < files.Length; i++)
all += "\n" + files[i].FullName.Trim() + "end\n";
}
}
private void button3_Click(object sender, EventArgs e)
{
this學網,收藏本篇文章 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
>.folderBrowserDialog2.ShowDialog();
this.dir = this.folderBrowserDialog2.SelectedPath;
this.ShowAll(dir);
//MessageBox.Show(GetTable("select * from titles").Rows[0]["test"].ToString());
}
歡迎光臨學網,點擊這裡查看更多文章教程 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]