Beispiel #1
0
 /// <summary>
 /// 执行查询语句,返回DataSet
 /// </summary>
 /// <param name="SQLString">查询语句</param>
 /// <returns>DataSet</returns>
 public DataSet Query(string SQLString, params SQLiteParameter[] cmdParms)
 {
     using (var connection = new SQLiteConnection(this.connectionString))
     {
         using (var cmd = new SQLiteCommand())
         {
             this.PrepareCommand(cmd, connection, null, SQLString, cmdParms);
             using (var da = new SQLiteDataAdapter(cmd))
             {
                 try
                 {
                     DataSet ds = new DataSet();
                     da.Fill(ds, "ds");
                     DbHelperCommon.AddDataSetTableNames(SQLString, ref ds);
                     cmd.Parameters.Clear();
                     return(ds);
                 }
                 catch (SQLiteException ex)
                 {
                     throw new Exception(ex.Message);
                 }
                 finally
                 {
                     da.Dispose();
                     cmd.Dispose();
                     connection.Close();
                 }
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 执行查询语句,返回DataSet
        /// </summary>
        /// <param name="SQLString">查询语句</param>
        /// <returns>DataSet</returns>
        public DataSet Query(string SQLString)
        {
            using (var connection = new SQLiteConnection(this.connectionString))
            {
                connection.Open();
                using (var command = new SQLiteDataAdapter(SQLString, connection))
                {
                    try
                    {
                        DataSet ds = new DataSet();

                        command.Fill(ds, "ds");
                        DbHelperCommon.AddDataSetTableNames(SQLString, ref ds);

                        return(ds);
                    }
                    catch (SQLiteException ex)
                    {
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        command.Dispose();
                        connection.Close();
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 执行查询语句,返回DataSet
        /// </summary>
        /// <param name="SQLString">查询语句</param>
        /// <returns>DataSet</returns>
        public DataSet Query(string SQLString, int timeoutseconds, params SqlParameter[] cmdParms)
        {
            using (SqlConnection connection = new SqlConnection(this.connectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandTimeout = timeoutseconds;
                    PrepareCommand(cmd, connection, null, SQLString, cmdParms);
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        DataSet ds = new DataSet();
                        try
                        {
                            da.Fill(ds, "ds");
                            DbHelperCommon.AddDataSetTableNames(SQLString, ref ds);

                            return(ds);
                        }
                        catch (System.Data.SqlClient.SqlException ex)
                        {
                            throw new Exception(ex.Message);
                        }
                    }
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// 执行查询语句,返回DataSet
 /// </summary>
 /// <param name="SQLString">查询语句</param>
 /// <returns>DataSet</returns>
 public DataSet Query(string SQLString, params OleDbParameter[] cmdParms)
 {
     using (OleDbConnection connection = new OleDbConnection(connectionString))
     {
         using (OleDbCommand cmd = new OleDbCommand())
         {
             PrepareCommand(cmd, connection, null, SQLString, cmdParms);
             using (OleDbDataAdapter da = new OleDbDataAdapter(cmd))
             {
                 DataSet ds = new DataSet();
                 try
                 {
                     da.Fill(ds, "ds");
                     DbHelperCommon.AddDataSetTableNames(SQLString, ref ds);
                     return(ds);
                 }
                 catch (OleDbException ex)
                 {
                     throw new Exception(ex.Message);
                 }
                 finally
                 {
                     cmd.Dispose();
                     connection.Dispose();
                 }
             }
         }
     }
 }
Beispiel #5
0
 /// <summary>
 /// 执行查询语句,返回DataSet
 /// </summary>
 /// <param name="SQLString">查询语句</param>
 /// <returns>DataSet</returns>
 public static DataSet Query(string SQLString)
 {
     using (OleDbConnection connection = new OleDbConnection(connectionString))
     {
         DataSet ds = new DataSet();
         try
         {
             connection.Open();
             using (OleDbDataAdapter command = new OleDbDataAdapter(SQLString, connection))
             {
                 command.Fill(ds, "ds");
                 DbHelperCommon.AddDataSetTableNames(SQLString, ref ds);
                 return(ds);
             }
         }
         catch (System.Data.OleDb.OleDbException ex)
         {
             throw new Exception(ex.Message);
         }
     }
 }
Beispiel #6
0
        public static DataSet Query(string SQLString, int Times)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    using (SqlDataAdapter command = new SqlDataAdapter(SQLString, connection))
                    {
                        DataSet ds = new DataSet();
                        connection.Open();

                        command.SelectCommand.CommandTimeout = Times;
                        command.Fill(ds, "ds");
                        DbHelperCommon.AddDataSetTableNames(SQLString, ref ds);
                        return(ds);
                    }
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// 执行查询语句,返回DataSet
 /// </summary>
 /// <param name="SQLString">查询语句</param>
 /// <returns>DataSet</returns>
 public static DataSet Query(string SQLString, params SqlParameter[] cmdParms)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         using (SqlCommand cmd = new SqlCommand())
         {
             PrepareCommand(cmd, connection, null, SQLString, cmdParms);
             using (SqlDataAdapter da = new SqlDataAdapter(cmd))
             {
                 DataSet ds = new DataSet();
                 try
                 {
                     da.Fill(ds, "ds");
                     DbHelperCommon.AddDataSetTableNames(SQLString, ref ds);
                     return(ds);
                 }
                 catch (SqlException ex)
                 {
                     throw new Exception(ex.Message);
                 }
             }
         }
     }
 }