public static String getConnStr(String DBType) { String connStr = ""; if (DBType.Contains(".xlsx")) { connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + DBType + ";" + ";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=0\""; } else if (DBType.Contains(".xls")) { connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + DBType + ";" + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=0\""; } else { try { connStr = ConfigUtil.GetConnectionString(DBType.ToUpper()); String privoder = ConfigUtil.GetProviderName(DBType.ToUpper()); if (privoder != "System.Data.SqlClient") { connStr = "Provider=" + privoder + ";" + ConfigUtil.GetConnectionString(DBType.ToUpper()); } //System.Windows.Forms.MessageBox.Show(connStr); } catch (Exception e) { //System.Windows.Forms.MessageBox.Show("链接类型:"+DBType+"不存在"); AlertUtil.Show("error", e.ToString()); } } return(connStr); }
/// <summary> /// /// </summary> /// <param name="DBType">服务器</param> /// <param name="Sql">Sql语句</param> /// <param name="sqlType">PROCEDURE时为存储过程,其他时候为SQL语句</param> /// <returns></returns> public static DbDataAdapter getDbDataAdapter(String DBType, String Sql, String sqlType, DbConnection dbConn) { DbDataAdapter da = null; try { switch (DBType.ToUpper()) { case "AS400": da = getOleDbDataAdapter(dbConn, Sql, sqlType); break; case "SRFSQL": case "ICHART3T": case "ICHART3D": default: da = getSqlDataAdapter(dbConn, Sql, sqlType); break; } } catch (Exception e) { AlertUtil.Show("error", e.ToString()); } return(da); }
public static string GetAttributeValue(string node, string key, String name) { string value = string.Empty; try { if (File.Exists(@"\\ichart3t\发行文件\DBConn.config")) { XmlDocument xml = new XmlDocument(); xml.Load(file); XmlNode xNode = xml.SelectSingleNode(node); XmlElement element = (XmlElement)xNode.SelectSingleNode("//add[@name='" + key + "']"); value = element.GetAttribute(name).ToString(); return(value); } else { AlertUtil.Show("error", "DBConfig无法定位!!"); return(null); } } catch { AlertUtil.Show("error", "DBConfig异常!"); } return(value); }