2、数据库帮助类

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;

namespace SQLServerDAL
{
     public abstract class SqlHelper
    {

       public static readonly string ConnectionStringLocalTransaction =ConfigurationManager.ConnectionStrings["SQLConnectionStirng"].ConnectionString;

         public static SqlDataReader Exefdn(string scon, CommandType ctype, string SQL,SqlParameter param)
         { 
             SqlCommand cm = new SqlCommand();
             SqlConnection con = new SqlConnection(scon);
             try
             {
              
                 if (con.State != ConnectionState.Open)
                 {
                     con.Open();
                 }
                 cm.Connection = con;
                 cm.CommandText = SQL;               
                 cm.CommandType = ctype;
              

                 if (param != null)
                 {                   
                     cm.Parameters.Add(param);
                   
                 }
                 SqlDataReader dr = cm.ExecuteReader(CommandBehavior.CloseConnection);
                 cm.Parameters.Clear();
                 return dr;

             }
             catch (Exception)
             {
                 con.Close();
                 throw;
             }
         }
    }
}

posted on 2008-07-17 12:21  自己  阅读(374)  评论(0编辑  收藏  举报