コード例 #1
0
        public List <ACTable> GetSelectTable()
        {
            List <ACTable> tables = new List <ACTable>();

            foreach (ListViewItem lvItem in lvwTable.SelectedItems)
            {
                tables.Add(lvItem.Tag as ACTable);
            }

            MySqlConnection conn = GetConn();

            foreach (ACTable table in tables)
            {
                table.Fields.Clear();

                //string sql = "select [name],[type] from [syscolumns] where [id] = " + table.Id;
                string sql = "Select COLUMN_NAME, DATA_TYPE " +
                             " from INFORMATION_SCHEMA.COLUMNS " +
                             " Where table_name = '" + table.Name + "' " +
                             " AND table_schema = '" + table.DatabaseName + "'";
                MySqlDataAdapter adapter = new MySqlDataAdapter(sql, conn);
                DataSet          ds      = new DataSet();
                adapter.Fill(ds);
                DataTable dt = ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {
                    ACField field = new ACField();
                    field.Name = Convert.ToString(dr[0]);
                    //field.Comment = Convert.ToString(dr[4]);
                    //string typeStr = Convert.ToString(dr[3]);
                    ////字符类型字段
                    //if (typeStr == "nvarchar")
                    //{
                    //    field.Type = ACFieldType.text;
                    //}
                    ////数值类型字段
                    //else if (typeStr == "int")
                    //{
                    //    field.Type = ACFieldType.number;
                    //}
                    ////其他类型
                    //else
                    //{
                    //    field.Type = ACFieldType.other;
                    //}

                    table.Fields.Add(field);
                }
            }

            conn.Close();

            return(tables);
        }
コード例 #2
0
ファイル: FormMySQL.cs プロジェクト: canneljls/JLSAutoCode
        public List<ACTable> GetSelectTable()
        {
            List<ACTable> tables = new List<ACTable>();
            foreach (ListViewItem lvItem in lvwTable.SelectedItems)
            {
                tables.Add(lvItem.Tag as ACTable);
            }

            MySqlConnection conn = GetConn();

            foreach (ACTable table in tables)
            {
                table.Fields.Clear();

                //string sql = "select [name],[type] from [syscolumns] where [id] = " + table.Id;
                string sql = "Select COLUMN_NAME, DATA_TYPE " +
                    " from INFORMATION_SCHEMA.COLUMNS " +
                    " Where table_name = '" + table.Name + "' " +
                    " AND table_schema = '" + table.DatabaseName + "'";
                MySqlDataAdapter adapter = new MySqlDataAdapter(sql, conn);
                DataSet ds = new DataSet();
                adapter.Fill(ds);
                DataTable dt = ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {
                    ACField field = new ACField();
                    field.Name = Convert.ToString(dr[0]);
                    //field.Comment = Convert.ToString(dr[4]);
                    //string typeStr = Convert.ToString(dr[3]);
                    ////字符类型字段
                    //if (typeStr == "nvarchar")
                    //{
                    //    field.Type = ACFieldType.text;
                    //}
                    ////数值类型字段
                    //else if (typeStr == "int")
                    //{
                    //    field.Type = ACFieldType.number;
                    //}
                    ////其他类型
                    //else
                    //{
                    //    field.Type = ACFieldType.other;
                    //}

                    table.Fields.Add(field);
                }
            }

            conn.Close();

            return tables;
        }
コード例 #3
0
        public List <ACTable> GetSelectTable()
        {
            List <ACTable> tables = new List <ACTable>();

            foreach (ListViewItem lvItem in lvwTable.SelectedItems)
            {
                tables.Add(lvItem.Tag as ACTable);
            }

            OleDbConnection conn = GetConn();

            foreach (ACTable table in tables)
            {
                table.Fields.Clear();

                //string sql = "select [name],[type] from [syscolumns] where [id] = " + table.Id;
                string sql = "select col.name as ColumnName, col.max_length as DataLength,col.is_nullable as IsNullable, " + "t.name as DataType, ep.value as Description  " +
                             " from sys.objects obj " +
                             "inner join sys.columns col " +
                             "on obj.object_id=col.object_id " +
                             "left join sys.types t " +
                             "on t.user_type_id=col.user_type_id " +
                             "left join sys.extended_properties ep " +
                             "on ep.major_id=obj.object_id  " +
                             "and ep.minor_id=col.column_id " +
                             "and ep.name='MS_Description' " +
                             "where obj.name='" + table.Name + "'";
                OleDbDataAdapter adapter = new OleDbDataAdapter(sql, conn);
                DataSet          ds      = new DataSet();
                adapter.Fill(ds);
                DataTable dt = ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {
                    ACField field = new ACField();
                    field.Name    = Convert.ToString(dr[0]);
                    field.Comment = Convert.ToString(dr[4]);
                    string typeStr = Convert.ToString(dr[3]);
                    //字符类型字段
                    if (typeStr == "nvarchar")
                    {
                        field.Type = ACFieldType.text;
                    }
                    //数值类型字段
                    else if (typeStr == "int")
                    {
                        field.Type = ACFieldType.number;
                    }
                    //其他类型
                    else
                    {
                        field.Type = ACFieldType.other;
                    }

                    table.Fields.Add(field);
                }
            }

            conn.Close();

            return(tables);
        }
コード例 #4
0
        public List<ACTable> GetSelectTable()
        {
            List<ACTable> tables = new List<ACTable>();
            foreach (ListViewItem lvItem in lvwTable.SelectedItems)
            {
                tables.Add(lvItem.Tag as ACTable);
            }

            OleDbConnection conn = GetConn();

            foreach (ACTable table in tables)
            {
                table.Fields.Clear();

                //string sql = "select [name],[type] from [syscolumns] where [id] = " + table.Id;
                string sql = "select col.name as ColumnName, col.max_length as DataLength,col.is_nullable as IsNullable, " + "t.name as DataType, ep.value as Description  " +
                    " from sys.objects obj " +
                     "inner join sys.columns col " +
                     "on obj.object_id=col.object_id " +
                     "left join sys.types t " +
                     "on t.user_type_id=col.user_type_id " +
                     "left join sys.extended_properties ep " +
                     "on ep.major_id=obj.object_id  " +
                     "and ep.minor_id=col.column_id " +
                     "and ep.name='MS_Description' " +
                     "where obj.name='" + table.Name + "'";
                OleDbDataAdapter adapter = new OleDbDataAdapter(sql, conn);
                DataSet ds = new DataSet();
                adapter.Fill(ds);
                DataTable dt = ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {                  
                    ACField field = new ACField();
                    field.Name = Convert.ToString(dr[0]);
                    field.Comment = Convert.ToString(dr[4]);
                    string typeStr = Convert.ToString(dr[3]);
                    //字符类型字段
                    if (typeStr == "nvarchar")
                    {
                        field.Type = ACFieldType.text;
                    }
                    //数值类型字段
                    else if (typeStr == "int")
                    {
                        field.Type = ACFieldType.number;
                    }
                    //其他类型
                    else
                    {
                        field.Type = ACFieldType.other;
                    }

                    table.Fields.Add(field);
                }
            }

            conn.Close();

            return tables;
        }