資源簡介
平時用得到的工具,源碼也提供了!不能生成文件,只能生成代碼,沒有美工只滿足實用,可以自己改一下。
代碼片段和文件信息
using?MySql.Data.MySqlClient;
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Data.SqlClient;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
namespace?MYSQL實體類生成
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????string?connectStr?=?“server=“?+?textBox1.Text?+?“;port=3306;user=“?+?textBox2.Text?+?“;password=“?+?textBox3.Text?+?“;“;
????????????string?sqlstr?=?“select?TABLE_SCHEMA?from?information_schema.tables?where?table_type=‘base?TABLE‘?GROUP?BY?‘TABLE_SCHEMA‘;“;???//SQL語句
????????????DataSet?Ds?=?SQLHelper.GetDataSet(connectStrsqlstr?CommandType.Text?null);
????????????comboBox1.DataSource?=?Ds.Tables[0];
????????????comboBox1.DisplayMember?=?“TABLE_SCHEMA“;
????????????comboBox1.ValueMember?=?“TABLE_SCHEMA“;
????????}
????????private?void?comboBox1_SelectedIndexChanged(object?sender?EventArgs?e)
????????{
????????????string?connectStr?=?“server=“?+?textBox1.Text?+?“;port=3306;user=“?+?textBox2.Text?+?“;password=“?+?textBox3.Text?+?“;“;
????????????string?sqlstr?=?“select?table_nametable_rows?from?information_schema.tables?where?table_schema=‘“?+?comboBox1?.Text+?“‘?and?table_type=‘base?table‘;“;???//SQL語句
????????????DataSet?Ds?=?SQLHelper.GetDataSet(connectStr?sqlstr?CommandType.Text?null);
????????????comboBox2.DataSource?=?Ds.Tables[0];
????????????comboBox2.DisplayMember?=?“table_name“;
????????????comboBox2.ValueMember?=?“table_name“;????
????????}
????????private?void?comboBox2_SelectedIndexChanged(object?sender?EventArgs?e)
????????{
????????????richTextBox1.Text?=?““;
????????????richTextBox2.Text?=?““;
????????????richTextBox3.Text?=?““;
????????????StringBuilder?sb?=?new?StringBuilder();?
????????????string?connectStr?=?“server=“?+?textBox1.Text?+?“;port=3306;user=“?+?textBox2.Text?+?“;password=“?+?textBox3.Text?+?“;“;
????????????string?sqlstr?=?“select?column_nameORDINAL_POSITIONIS_NULLABLEDATA_TYPECOLUMN_COMMENT?from?information_schema.columns?where?table_schema=‘“?+?comboBox1.Text?+?“‘?and?table_name=‘“?+?comboBox2.Text?+?“‘;“;???//SQL語句
????????????MySqlDataReader?dr?=?SQLHelper.ExecuteReader(connectStr?sqlstr?CommandType.Text?null);
????????????while?(dr.Read())?{
????????????????String[]?sp?=?dr[“column_name“].ToString().Split(‘_‘);
????????????????richTextBox1.AppendText(sp[sp.Length-1]?+?“\r\n“);
????????????????String?dx?=?sp[sp.Length?-?1].Substring(0?1).ToUpper()?+?sp[sp.Length?-?1].Substring(1);
????????????????if?(dr[“DATA_TYPE“].ToString()?==?“int“)
????????????????{?
????????????????????richTextBox2.AppendText(“private?int?“?+?sp[sp.Length?-?1]?+?“=0;//“?+?dr[“COLUMN_COMMENT“]?+?“\r\n“);
????????????????????String?ass?=?“public?int?“?+?dx?+?“\n“?+
????????????????????“{\n“?+
評論
共有 條評論