尝试着写自己的代码生成器(5)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-26 22:00 点击:次
111 foreach (string colname in ColumnNames)
112 {
113 sb.AppendLine(",new SqlParameter(\""+colname+"\",model."+colname+")");
114 }
115 sb.AppendLine(");");
116 sb.AppendLine("return Convert.ToInt32(obj);");
117 MessageBox.Show(sb.ToString());
118 }
119
120 /// <summary>
121 /// 生成Model
122 /// </summary>
123 /// <param name="TableName">被选中的表名</param>
124 /// <returns>model模型</returns>
125 private void CreateModel(string TableName)
126 {
127 DataTable dt_column = ExecuteDataTable("select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=@tablename and Column_Name<>'id'", new SqlParameter("tablename", TableName));
128 StringBuilder sb = new StringBuilder();
129 sb.AppendLine("Class" + TableName);
130 sb.AppendLine("{");
131 foreach (DataRow row in dt_column.Rows)
132 {
133 string dt_Col = (string)row["COLUMN_NAME"];
134 string col_Type = (string)row["DATA_TYPE"];
135 string CsType = StrToCsharp(col_Type);
136 sb.AppendLine("Public " + CsType + " " + dt_Col + "{get;set;}");
137 }
138 sb.AppendLine("}");
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>