コード例 #1
0
ファイル: MSSQLCreate.cs プロジェクト: lyxlove/CreateEntity
        public string CreateEntity(string strTableName)
        {
            string strSql = string.Format("Select systypes.name AS TypeName,SysColumns.name AS ColName,ISNULL(sys.extended_properties.value,'') as Remark From SysColumns" +
                                          " LEFT JOIN systypes ON SysColumns.xtype = systypes.xtype" +
                                          " LEFT JOIN sys.extended_properties ON sys.extended_properties.major_id = SysColumns.id AND sys.extended_properties.minor_id = SysColumns.colorder" +
                                          " Where id = Object_Id('{0}')", strTableName);
            SqlCommand sqlCommand = new SqlCommand(strSql, sqlConnection);

            if (sqlConnection.State == System.Data.ConnectionState.Closed)
            {
                sqlConnection.Open();
            }
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
            List <string> listColName   = new List <string>();
            List <string> listColRemark = new List <string>();
            List <string> listType      = new List <string>();

            while (sqlDataReader.Read())
            {
                listColName.Add(sqlDataReader["ColName"].ToString());
                listColRemark.Add(sqlDataReader["Remark"].ToString());
                listType.Add(GetCSharpDataType(sqlDataReader["TypeName"].ToString()));
            }
            sqlDataReader.Close();

            return(EntityCreator.CreateEntity(strTableName, listColName, listType, listColRemark));
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: lyxlove/CreateEntity
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string  strTableName = combTableList.Text;
            ICreate create       = new MSSQLCreate();

            create.ConnDB();
            string str = create.CreateEntity(strTableName);

            EntityCreator.SaveStrToFile(str, strTableName);
        }