Exemple #1
0
        /// <summary>
        /// 返回查询结果的DataTable对象
        /// </summary>
        /// <param name="sql">sql字符串</param>
        /// <param name="as_param">参数 如as_param1="@id=123"</param>
        /// <returns>对应的Int32对象,失败返回-1</returns>
        public DataTable ExecuteScalarDataTable(string sql, params string[] as_param)
        {
            SqlErr = string.Empty;
            ExeNum++;
            DataTable ldt = null;

            try
            {
                cmd.Connection  = conn;
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Clear();
                SQLiteParameter[] P = SQLiteHelper.GetSQLiteParameter(as_param);
                if (P != null)
                {
                    cmd.Parameters.AddRange(P);
                }
                using (SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd))
                {
                    sda.Fill(ldt);
                }
                cmd.Parameters.Clear();
                return(ldt);
            }
            catch (Exception ex)
            {
                SqlErr = ex.Message;
                SQLiteLog.WriteLine("dbca", SqlErr, sql, as_param);
                return(null);
            }
        }
Exemple #2
0
 /// <summary>
 /// 执行SQL命令
 /// </summary>
 /// <param name="sql">sql字符串</param>
 /// <param name="as_param">参数 如as_param1="@id=123"</param>
 /// <returns>返回受影响行</returns>
 public int ExecuteNonQuery(string sql, params string[] as_param)
 {
     SqlErr = string.Empty;
     ExeNum++;
     try
     {
         cmd.Connection  = conn;
         cmd.CommandText = sql;
         cmd.CommandType = CommandType.Text;
         cmd.Parameters.Clear();
         SQLiteParameter[] P = SQLiteHelper.GetSQLiteParameter(as_param);
         if (P != null)
         {
             cmd.Parameters.AddRange(P);
         }
         int rows = cmd.ExecuteNonQuery();
         cmd.Parameters.Clear();
         return(rows);
     }
     catch (Exception ex)
     {
         SqlErr = ex.Message;
         SQLiteLog.WriteLine("dbca", SqlErr, sql, as_param);
         return(-1);
     }
 }
Exemple #3
0
 /// <summary>
 /// 构造方法
 /// </summary>
 public SQLiteDbca()
 {
     try
     {
         conn = new SQLiteConnection(dbconnStr);
         conn.Open();
         cmd             = new SQLiteCommand();
         tran            = conn.BeginTransaction();
         cmd.Connection  = conn;
         cmd.Transaction = tran;
     }
     catch (Exception ex)
     {
         SqlErr = ex.Message;
         SQLiteLog.WriteLine("dbca", ex.Message, "dbconnStr:" + dbconnStr, "");
     }
 }
Exemple #4
0
 /// <summary>
 /// 返回查询字符串第一个匹配项
 /// </summary>
 /// <param name="sql">sql字符串</param>
 /// <param name="as_param">参数 如as_param1="@id=123"</param>
 /// <returns>返回对应值</returns>
 internal object ExecuteScalarObj(string sql, params string[] as_param)
 {
     SqlErr = string.Empty;
     ExeNum++;
     try
     {
         cmd.Parameters.Clear();
         SQLiteParameter[] P = SQLiteHelper.GetSQLiteParameter(as_param);
         if (P != null)
         {
             cmd.Parameters.AddRange(P);
         }
         object o = cmd.ExecuteScalar();
         cmd.Parameters.Clear();
         return(o);
     }
     catch (Exception ex)
     {
         SqlErr = ex.Message;
         SQLiteLog.WriteLine("dbca", SqlErr, sql, as_param);
         return(null);
     }
 }