杂志目录(数据库访问部分)

发表于:2007-06-30来源:作者:点击数: 标签:
using System; using System.Configuration; using System.Data; using System.Data.SqlClient; namespace cj168.DataAccess { public class MagsDB { //SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings[ConnectionString
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;


namespace cj168.DataAclearcase/" target="_blank" >ccess
{
    
    public class MagsDB
    {
        //SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

        public void openConn()
        {
            //myConnection.Open();
    
        }
        

        public void closeConn()
        {
            
            //myConnection.Close();
    
            
        }


        public SqlDataReader GetMagIssue(int magID, int magYear)
        {
            SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            
            SqlCommand myCommand = new SqlCommand("GetMagIssue", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;


            SqlParameter parameterMagID = new SqlParameter("@MagID", SqlDbType.Int, 4);
            parameterMagID.Value = magID;
            myCommand.Parameters.Add(parameterMagID);


            SqlParameter parameterMagYear = new SqlParameter("@MagYear", SqlDbType.Int, 4);
            parameterMagYear.Value = magYear;
            myCommand.Parameters.Add(parameterMagYear);

            
            myConnection.Open();
            SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            //SqlDataReader result = myCommand.ExecuteReader();
            
            
            return result;
        }

        public DataSet GetMagIssueCat(int magID, int magYear, int yearIssue)
        {
            SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlDataAdapter myCommand = new SqlDataAdapter("GetMagIssueCat", myConnection);
            
            myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;


            SqlParameter parameterMagID = new SqlParameter("@MagID", SqlDbType.Int, 4);
            parameterMagID.Value = magID;
            myCommand.SelectCommand.Parameters.Add(parameterMagID);


            SqlParameter parameterMagYear = new SqlParameter("@MagYear", SqlDbType.Int, 4);
            parameterMagYear.Value = magYear;
            myCommand.SelectCommand.Parameters.Add(parameterMagYear);


            SqlParameter parameterYearIssue = new SqlParameter("@YearIssue", SqlDbType.Int, 4);
            parameterYearIssue.Value = yearIssue;
            myCommand.SelectCommand.Parameters.Add(parameterYearIssue);

            DataSet myDataSet = new DataSet();

            //myConnection.Open();
            myCommand.Fill(myDataSet);
            //SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            //SqlDataReader result = myCommand.ExecuteReader();
            //return result;
            return myDataSet;
        }

        public DataSet GetSubCat(int magID, int magYear, int yearIssue, int catID)
        {
            SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlDataAdapter myCommand = new SqlDataAdapter("GetSubCat", myConnection);
            myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;


            SqlParameter parameterMagID = new SqlParameter("@MagID", SqlDbType.Int, 4);
            parameterMagID.Value = magID;
            myCommand.SelectCommand.Parameters.Add(parameterMagID);


            SqlParameter parameterMagYear = new SqlParameter("@MagYear", SqlDbType.Int, 4);
            parameterMagYear.Value = magYear;
            myCommand.SelectCommand.Parameters.Add(parameterMagYear);


            SqlParameter parameterYearIssue = new SqlParameter("@YearIssue", SqlDbType.Int, 4);
            parameterYearIssue.Value = yearIssue;
            myCommand.SelectCommand.Parameters.Add(parameterYearIssue);

            SqlParameter parameterCatID = new SqlParameter("@CatID", SqlDbType.Int, 4);
            parameterCatID.Value = catID;
            myCommand.SelectCommand.Parameters.Add(parameterCatID);


            DataSet myDataSet = new DataSet();

            //myConnection.Open();
            //SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            //SqlDataReader result = myCommand.ExecuteReader();
            //return result;
            myCommand.Fill(myDataSet);
            return myDataSet;
            
            
        }


        public DataSet GetMagArtTitle(int catIssueID)
        {
            SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlDataAdapter myCommand = new SqlDataAdapter("GetMagArtTitle", myConnection);
            myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
         
            SqlParameter parameterCatIssueID = new SqlParameter("@CatIssueID", SqlDbType.Int, 4);
            parameterCatIssueID.Value = catIssueID;
            myCommand.SelectCommand.Parameters.Add(parameterCatIssueID);

            //myConnection.Open();
            //SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            //SqlDataReader result = myCommand.ExecuteReader();
            //return result;
            DataSet myDataSet = new DataSet();
            myCommand.Fill(myDataSet);
            return myDataSet;
            
        }

        public DataSet GetArtDetail(int txtID)
        {
            SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlDataAdapter myCommand = new SqlDataAdapter("GetArtDetail", myConnection);
            myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
         
            SqlParameter parameterTxtID = new SqlParameter("@txtID", SqlDbType.Int, 4);
            parameterTxtID.Value = txtID;
            myCommand.SelectCommand.Parameters.Add(parameterTxtID);

            //myConnection.Open();
            //SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            //SqlDataReader result = myCommand.ExecuteReader();
            //return result;
            DataSet myDataSet = new DataSet();
            myCommand.Fill(myDataSet,"ArtDetail");
            return myDataSet;
            
        }

    }



        /*

        public SqlDataReader GetMagIssue(int magID, int magYear, SqlConnection myConnection)
        {
            //SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            //myConnection.Open();
            SqlCommand myCommand = new SqlCommand("GetMagIssue", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;


            SqlParameter parameterMagID = new SqlParameter("@MagID", SqlDbType.Int, 4);
            parameterMagID.Value = magID;
            myCommand.Parameters.Add(parameterMagID);


            SqlParameter parameterMagYear = new SqlParameter("@MagYear", SqlDbType.Int, 4);
            parameterMagYear.Value = magYear;
            myCommand.Parameters.Add(parameterMagYear);

            
            //myConnection.Open();
            SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            //SqlDataReader result = myCommand.ExecuteReader();
            
            
            return result;
        }

        public SqlDataReader GetMagIssueCat(int magID, int magYear, int yearIssue, SqlConnection myConnection)
        {
            //SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand myCommand = new SqlCommand("GetMagIssueCat", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;


            SqlParameter parameterMagID = new SqlParameter("@MagID", SqlDbType.Int, 4);
            parameterMagID.Value = magID;
            myCommand.Parameters.Add(parameterMagID);


            SqlParameter parameterMagYear = new SqlParameter("@MagYear", SqlDbType.Int, 4);
            parameterMagYear.Value = magYear;
            myCommand.Parameters.Add(parameterMagYear);


            SqlParameter parameterYearIssue = new SqlParameter("@YearIssue", SqlDbType.Int, 4);
            parameterYearIssue.Value = yearIssue;
            myCommand.Parameters.Add(parameterYearIssue);

            //myConnection.Open();
            SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            //SqlDataReader result = myCommand.ExecuteReader();
            

            return result;
        }

        public SqlDataReader GetSubCat(int magID, int magYear, int yearIssue, int catID, SqlConnection myConnection)
        {
            //SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand myCommand = new SqlCommand("GetSubCat", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;


            SqlParameter parameterMagID = new SqlParameter("@MagID", SqlDbType.Int, 4);
            parameterMagID.Value = magID;
            myCommand.Parameters.Add(parameterMagID);


            SqlParameter parameterMagYear = new SqlParameter("@MagYear", SqlDbType.Int, 4);
            parameterMagYear.Value = magYear;
            myCommand.Parameters.Add(parameterMagYear);


            SqlParameter parameterYearIssue = new SqlParameter("@YearIssue", SqlDbType.Int, 4);
            parameterYearIssue.Value = yearIssue;
            myCommand.Parameters.Add(parameterYearIssue);

            SqlParameter parameterCatID = new SqlParameter("@CatID", SqlDbType.Int, 4);
            parameterCatID.Value = catID;
            myCommand.Parameters.Add(parameterCatID);



            //myConnection.Open();
            SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            //SqlDataReader result = myCommand.ExecuteReader();
            

            return result;
            
        }


        public SqlDataReader GetMagArtTitle(int catIssueID, SqlConnection myConnection)
        {
            //SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand myCommand = new SqlCommand("GetMagArtTitle", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;
         
            SqlParameter parameterCatIssueID = new SqlParameter("@CatIssueID", SqlDbType.Int, 4);
            parameterCatIssueID.Value = catIssueID;
            myCommand.Parameters.Add(parameterCatIssueID);

            //myConnection.Open();
            SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            //SqlDataReader result = myCommand.ExecuteReader();
                    
            return result;
            
        }

    }
    */

    /// <summary>
    /// Summary description for WebCustomControl1.
    /// </summary>
    
    
}

原文转自:http://www.ltesting.net