|  |  |  | 
|---|
|  |  |  | //string strSql = $"SELECT COLUMN_NAME as ColumnName, COLUMN_TYPE as DataType, IS_NULLABLE as IsNullable, CHARACTER_MAXIMUM_LENGTH as DataLength,COLUMN_COMMENT as Description " + | 
|---|
|  |  |  | //                       $"FROM INFORMATION_SCHEMA.COLUMNS " + | 
|---|
|  |  |  | //                       $"WHERE  TABLE_NAME = '{tableName}'"; | 
|---|
|  |  |  | string strSql = $"SELECT c.COLUMN_NAME as ColumnName, c.COLUMN_TYPE as DataType, c.IS_NULLABLE as IsNullable, c.CHARACTER_MAXIMUM_LENGTH as DataLength, c.COLUMN_COMMENT as Description, " + | 
|---|
|  |  |  | string strSql = $"SELECT  c.COLUMN_NAME as ColumnName, c.DATA_TYPE as DataType, c.IS_NULLABLE as IsNullable, c.CHARACTER_MAXIMUM_LENGTH as DataLength, c.COLUMN_COMMENT as Description,c.NUMERIC_SCALE as MyPrecision, " + | 
|---|
|  |  |  | $"CASE WHEN kcu.COLUMN_NAME IS NOT NULL THEN 'true' ELSE 'false' END AS IsPrimaryKey " + | 
|---|
|  |  |  | $"FROM INFORMATION_SCHEMA.COLUMNS c " + | 
|---|
|  |  |  | $"LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu " + | 
|---|
|  |  |  | 
|---|
|  |  |  | $"AND c.TABLE_NAME = kcu.TABLE_NAME " + | 
|---|
|  |  |  | $"AND c.COLUMN_NAME = kcu.COLUMN_NAME " + | 
|---|
|  |  |  | $"AND kcu.CONSTRAINT_NAME = 'PRIMARY' " + | 
|---|
|  |  |  | $"WHERE c.TABLE_NAME = '{tableName}'"; | 
|---|
|  |  |  | $"WHERE c.TABLE_NAME = '{tableName}'" + | 
|---|
|  |  |  | $"ORDER BY c.ORDINAL_POSITION"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ColumnModel> columnList = new List<ColumnModel>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | DataSet ds = MySqlHelper.Query(connStr, strSql); | 
|---|
|  |  |  | columnList = DataTableToList(ds.Tables[0]); | 
|---|
|  |  |  | //鍘婚噸鎿嶄綔 | 
|---|
|  |  |  | columnList = columnList.GroupBy(p => p.ColumnName).Select(g => g.First()).ToList(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | model.Description = dt.Rows[n]["Description"].ToString(); | 
|---|
|  |  |  | if (dt.Rows[n]["IsNullable"].ToString() != "") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if ((dt.Rows[n]["IsNullable"].ToString() == "1") || (dt.Rows[n]["IsNullable"].ToString().ToLower() == "true")) | 
|---|
|  |  |  | if ((dt.Rows[n]["IsNullable"].ToString() == "1") || (dt.Rows[n]["IsNullable"].ToString().ToLower() == "true") || (dt.Rows[n]["IsNullable"].ToString().ToLower() == "yes")) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | model.IsNullable = true; | 
|---|
|  |  |  | } | 
|---|