我的OleDBHelp,欢迎大家挑毛病. public class OleDBHelper { private static string connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString; public OleDBHelper() { }
#region 添加数据 /// <summary> /// 添加数据 /// </summary> /// <param name="tableName">表名</param> /// <param name="p">参数集合</param> /// <returns>返回指示是否添加成功的布尔值</returns> public static bool InsertData(string tableName, params OleDbParameter[] parameters) { string s; StringBuilder sql = new StringBuilder(string.Format("insert into [{0}](", tableName)); foreach (OleDbParameter pt in parameters) { s = pt.ParameterName; s = s.Substring(1, s.Length - 1); sql.Append("[" + s + "],"); } s = sql.ToString(); sql = new StringBuilder(string.Format("[{0}]) values(", s.Substring(0, s.Length - 1))); foreach (OleDbParameter pt in parameters) { sql.Append(pt.ParameterName + ","); } s = sql.ToString(); sql = new StringBuilder(s.Substring(0, s.Length - 1) + ")"); try { using (OleDbConnection con = new OleDbConnection(connectionString)) { con.Open(); OleDbCommand com = new OleDbCommand(sql.ToString(), con); com.Parameters.AddRange(parameters); int i = com.ExecuteNonQuery(); com.Parameters.Clear(); if (i == 0) return false; return true; } } catch (Exception e) { throw e; } } #endregion