
  
  public class DBHelper
  {
      static SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["Db"]);
  
      private 【DBHelper】()
      {
  
      }
      public static DataTable GetTable(string sql)
      {
  
          SqlDataAdapter sda = new 【SqlDataAdapter】(【sql】, conn);
          DataTable table = new 【DataTable】();
          sda.【Fill】(table);
          【return】 table;
      }
  
  
      public static DataTable GetTable(string sql, Hashtable ht)
      {
  
          SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
  
          foreach (【DictionaryEntry】 de in ht)
          {
              sda.SelectCommand.Parameters.【AddWithValue】(de.Key.ToString(), de.Value.ToString());
          }
    
          DataTable table = new DataTable();
          sda.Fill(table);
          return table;
      }
  
  
      // 普通sql语句，执行维护操作，没有参数
  
      public static int execSql(string sql)
      {
          int result;
          conn.【Open】();
          SqlCommand cmd = new SqlCommand(sql, 【conn】);
          try
          {
              result = cmd.【ExecuteNonQuery】();
          }
          【finally】
          {
              conn.Close();
  
          }
  
          return result;
      }
  
      /// 普通sql语句，执行维护操作，有参数
  
      public static int execSql(string sql, Hashtable ht)
      {
          int result;
  
          SqlCommand cmd = new SqlCommand(sql, conn);
          foreach (DictionaryEntry de in ht)
          {
              cmd.Parameters.AddWithValue(de.【Key】.ToString(), de.【Value】.ToString());
          }
          conn.Open();
          try
          {
  
              result = cmd.【ExecuteNonQuery】();
  
          }
          finally
          {
              conn.Close();
  
          }
          return result;
      }
  
  
      // 执行sql并返回执行结果中的第一列
      public static int execScalar(string sql)
      {
          int result;
          SqlCommand cmd = new SqlCommand(sql, conn);
          conn.Open();
          try
          {
              result = Convert.【ToInt32】(cmd.【ExecuteScalar】());
          }
          finally
          {
              conn.Close();
  
          }
          return result;
      }
      // 执行sql并返回执行结果中的第一列
      public static int execScalar(string sql, Hashtable ht)
      {
          int result;
  
          SqlCommand cmd = new SqlCommand(sql, conn);
  
             foreach (DictionaryEntry de in ht)
          {
              cmd.【Parameters】.AddWithValue(de.Key.ToString(), de.Value.ToString());
          }
          conn.Open();
          try
          {
              result = Convert.ToInt32(cmd.【ExecuteScalar】());
          }
          finally
          {
              conn.Close();
  
          }
          return result;
      }
  
  
  }
  

--答案--
   ExecuteScalar   finally   Value   DataTable   AddWithValue   ToInt32   return   ExecuteNonQuery   SqlDataAdapter   ExecuteNonQuery   DBHelper   DictionaryEntry   Parameters   ExecuteScalar