DataTable dtCompare = new DataTable();
dtCompare.Columns.Add("FieldName", typeof(string));
dtCompare.Columns.Add("FieldType", typeof(string));
dtCompare.Columns.Add("FieldSize", typeof(int));
dtCompare.Columns.Add("DbField", typeof(string));
dtCompare.PrimaryKey = new DataColumn[] { dtCompare.Columns["FieldName"] };
for (int i = 0; i < DtData.Columns.Count; i++)
{
DataRow dr = dtCompare.NewRow();
dr.ItemArray = new object[] {
DtData.Columns[i].ColumnName,
DtData.Columns[i].DataType.ToString()
};
dtCompare.Rows.Add(dr);
}
DataTable dtDb = con.GetSchema("Columns", new string[] { null, null, this.tableConfig.Table_Struct.TableName });
List<string> ls = new List<string>();
for (int i = 0; i < dtCompare.Rows.Count; i++)
{
DataRow dr = dtCompare.Rows[i];
string bz = "";
string filter = string.Format("COLUMN_NAME='{0}'", dr["FieldName"].ToString());
DataRow[] drDbs = dtDb.Select(filter);
if (null == drDbs || drDbs.Length == 0)
dr["DbField"] = "数据库表无对应字段";
if (dr["FieldType"].ToString().Equals("System.String"))
{
int len = 0;
for (int j = 0; j < DtData.Rows.Count; j++)
{
int len1 = DtData.Rows[j][dr["FieldName"].ToString()].ToString().Length;
if (len < len1)
{
len = len1;
}
}
dr["FieldSize"] = len;
if (null != drDbs && drDbs.Length > 0)
{
dr["DbField"] = "DB:" + drDbs[0]["CHARACTER_MAXIMUM_LENGTH"].ToString();
}
}
ls.Add(string.Format("{0}/{1}/{2}/{3}", dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString()));
}
string r = string.Join(Environment.NewLine, ls.ToArray());
throw new Exception(r);
qq_42678477 发布了115 篇原创文章 · 获赞 7 · 访问量 3万+ 私信 关注