using 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(){}"; } }}
下载C# 生成sql语句 小工具源码用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论