找传奇、传世资源到传世资源站!

C# 生成sql语句 小工具源码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboardusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace GenerateSql{ public partial class FrmMain : Form { public FrmMain() { InitializeComponent(); } /*QQ:631914123*/ //************************************************************************************ /// <summary> /// 查询sql /// </summary> private String loadListSql = String.Empty; /// <summary> /// 添加sql /// </summary> private String insertObjectSql = String.Empty; /// <summary> /// 修改sql /// </summary> private String updateObjectSql = String.Empty; /// <summary> /// 删除sql /// </summary> private String deleteObjectSql = String.Empty; /// <summary> /// 生成方法 /// </summary> private String GenerateMethodStr = String.Empty; private void btnGenerateSql_Click(object sender, EventArgs e) { GenerateSql(); } private void txtColumnName_Enter(object sender, EventArgs e) { txtColumnName.Text = "ID,NAME,SEX,PHONENUM,ADDRESS,EMAIL,IDENTITY,QQ,VX"; } /// <summary> /// 生成sql语句 /// </summary> private void GenerateSql() { txtGenerateSql.Text = ""; if (txtTableName != null && !txtTableName.Equals("")) { if (txtColumnName != null && !txtColumnName.Text.Equals("") && !txtColumnName.Text.Equals("列名用英文逗号隔开(,)")) { loadListSql = "String loadSql = \"select * from " txtTableName.Text "\""; txtGenerateSql.Text = "查询sql语句 select:\r\n" loadListSql ";\r\n"; txtGenerateSql.Text = "\r\n"; String[] splitColumnName = txtColumnName.Text.Split(','); insertObjectSql = "String insertObjectSql = \" insert into " txtTableName.Text "("; for (int i = 0; i < splitColumnName.Length; i ) { if ((splitColumnName.Length - 1) == i) insertObjectSql = splitColumnName[i]; else insertObjectSql = splitColumnName[i] ","; } insertObjectSql = ") values( "; for (int n = 0; n < splitColumnName.Length; n ) { if (n == 0) { insertObjectSql = splitColumnName[n] "={" n "},"; continue; } if ((n 1) == splitColumnName.Length) { insertObjectSql = splitColumnName[n] " = '{" n "}'"; break; } insertObjectSql = splitColumnName[n] " = '{" n "}',"; } insertObjectSql = ")\";"; txtGenerateSql.Text = "添加sql语句 insert:\r\n" insertObjectSql "\r\n"; txtGenerateSql.Text = "\r\n"; updateObjectSql = "String updateObjectSql = \"update " txtTableName.Text " set "; int num = 0; for (int j = 0; j <= splitColumnName.Length; j ) { if (j == 0) continue; if ((j 1) == splitColumnName.Length) { updateObjectSql = splitColumnName[j] " = '{" num "}'"; break; } updateObjectSql = splitColumnName[j] " = '{" num "}',"; num ; } num = 1; updateObjectSql = " where " splitColumnName[0] " = {" num "};"; txtGenerateSql.Text = "修改sql语句 update:\r\n" updateObjectSql; txtGenerateSql.Text = "\r\n"; deleteObjectSql = "String deleteObjectSql = \"delete from " txtTableName.Text " where " splitColumnName[0] " = {0}\";"; txtGenerateSql.Text = "\r\n"; txtGenerateSql.Text = "删除sql语句 delete:\r\n" deleteObjectSql; } else { loadListSql = "String loadSql = \"select * from " txtTableName.Text "\""; txtGenerateSql.Text = "查询sql语句 select:\r\n" loadListSql ";\r\n"; txtGenerateSql.Text = "\r\n"; MessageBox.Show("列名不输入你让我生成什么??????!!!!"); } } else MessageBox.Show("请输入表名!"); } /// <summary> /// 生成查询所有信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLoad_Click(object sender, EventArgs e) { GenerateLoad(); } /// <summary> /// 查询所有信息 /// </summary> private void GenerateLoad() { if (txtTableName != null && !txtTableName.Equals("")) { if (txtColumnName != null && !txtColumnName.Text.Equals("") && !txtColumnName.Text.Equals("列名用英文逗号隔开(,)")) { GenerateSql(); String[] splitColumnName = txtColumnName.Text.Split(','); txtGenerateSql.Text = "DataSet ds = sc.Select(\"select* from " txtTableName.Text "\");"; txtGenerateSql.Text = "\r\nforeach (DataTable dt in ds.Tables)\r\n{\r\n foreach (DataRow dr in dt.Rows)\r\n {"; txtGenerateSql.Text = "\r\n StudentInfo info = new StudentInfo();"; for (int i = 0; i < splitColumnName.Length; i ) { if (i == 0) { txtGenerateSql.Text = "\r\n info." splitColumnName[i] " = (int)dr[\"" splitColumnName[i] "\"];"; continue; } txtGenerateSql.Text = "\r\n info." splitColumnName[i] " = dr[\"" splitColumnName[i] "\"].ToString();"; if ((i 1) == splitColumnName.Length) txtGenerateSql.Text = "\r\n listInfo.Add(info);"; } } else MessageBox.Show("不输入列名你让我生成什么??????!!!"); } else MessageBox.Show("请大侠指路道明让我生成什么!!!!"); } /// <summary> /// 生成方法 /// </summary> private void GenerateMethod() { txtGenerateSql.Text = ""; txtGenerateSql.Text = "添加方法:"; GenerateMethodStr = "public void insert(){}"; } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复