Esempio n. 1
0
        private void But_choose_Click(object sender, EventArgs e)
        {
            string tablename = cob_tablename.Text.Trim();
            string sql       = "";
            string jdbcType  = cob_jdbctype.Text.Trim();
            string zdlx      = cob_buildtype.Text.Trim();

            if (zdlx == "")
            {
                MessageBox.Show("请先选择要生成的类型", "提示", MessageBoxButtons.OK);
                return;
            }
            DataTable dt = new DataTable();

            if (jdbcType == "sqlserver")
            {
                sql = "select j.table_name,j.column_name as name,j.column_description as describes,d.data_type as type from (select "
                      + "a.name as table_name,b.name as column_name,c.value as column_description from sys.tables a "
                      + "inner join sys.columns b on b.object_id = a.object_id left join sys.extended_properties c "
                      + "on c.major_id = b.object_id and c.minor_id = b.column_id where a.name = '" + tablename + "'"
                      + ") j left join information_schema.columns d on j.column_name=d.column_name "
                      + "where d.table_name = '" + tablename + "'";
                dt = sqlContent.GetTable(sql);
            }
            else if (jdbcType == "mysql")
            {
                sql = "select column_name as name,column_comment as describes,data_type as type from information_schema.columns where"
                      + " table_name='" + tablename + "'";
                dt = sqlContent.GetTable(sql);
            }

            DataTable table = new DataTable();

            table.Columns.Add("name");
            table.Columns.Add("type");
            table.Columns.Add("describes");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string name      = dt.Rows[i]["name"].ToString();
                string type      = dt.Rows[i]["type"].ToString();
                string describes = dt.Rows[i]["describes"].ToString();
                if (zdlx == "CSharp")
                {
                    type = sqlCreat.GetFieldTypeByCSharp(type);
                }
                else if (zdlx == "Java")
                {
                    type = sqlCreat.GetFieldTypeByJava(type);
                }
                DataRow row = table.NewRow();
                row["name"]      = name;
                row["type"]      = type;
                row["describes"] = describes;
                table.Rows.Add(row);
            }
            dgv_content.DataSource                 = table;
            dgv_content.Columns["name"].Width      = 200;
            dgv_content.Columns["type"].Width      = 200;
            dgv_content.Columns["describes"].Width = 500;
        }
Esempio n. 2
0
        private void But_Select_Click(object sender, EventArgs e)
        {
            string    sql = rtb_sql.Text.TrimEnd();
            DataTable dt  = sqlContent.GetTable(sql);

            dgv_content.DataSource = dt;
        }