public static T ConvertTo <T>(object data) { if (data == null || Convert.IsDBNull(data)) { return(default(T)); } object obj = MdConvertHelper.ConvertTo(data, typeof(T)); if (obj == null) { return(default(T)); } return((T)((object)obj)); }
public static string GetExcelFirstTableName(OleDbConnection connection) { string result = string.Empty; if (connection.State == ConnectionState.Closed) { connection.Open(); } DataTable oleDbSchemaTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); if (oleDbSchemaTable != null && oleDbSchemaTable.Rows.Count > 0) { result = MdConvertHelper.ConvertTo <string>(oleDbSchemaTable.Rows[0][2]); } return(result); }
public static List <string> GetExcelTablesName(OleDbConnection connection) { List <string> list = new List <string>(); if (connection.State == ConnectionState.Closed) { connection.Open(); } DataTable oleDbSchemaTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); if (oleDbSchemaTable != null && oleDbSchemaTable.Rows.Count > 0) { for (int i = 0; i < oleDbSchemaTable.Rows.Count; i++) { list.Add(MdConvertHelper.ConvertTo <string>(oleDbSchemaTable.Rows[i][2])); } } return(list); }
/// <summary> /// 实现各进制数间的转换。ConvertBase("15",10,16)表示将十进制数15转换为16进制的数。 /// </summary> /// <param name="value"></param> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public static string ConvertBase(string value, int from, int to) { if (!MdConvertHelper.IsBaseNumber(from)) { throw new ArgumentException("参数from只能是2,8,10,16四个值。"); } if (!MdConvertHelper.IsBaseNumber(to)) { throw new ArgumentException("参数to只能是2,8,10,16四个值。"); } int value2 = Convert.ToInt32(value, from); string text = Convert.ToString(value2, to); if (to == 2) { switch (text.Length) { case 3: text = "00000" + text; break; case 4: text = "0000" + text; break; case 5: text = "000" + text; break; case 6: text = "00" + text; break; case 7: text = "0" + text; break; } } return(text); }