这里的类名叫ClsDbOper:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Text;
using System.Data.SqlClient;
using System.Windows.Forms;
///
/// ClsDbOper 的摘要说明
///
public class ClsDbOper
{
public static string strSqlConn = System.Configuration.ConfigurationSettings.AppSettings["DbConnString"];// "Data Source=.;Initial Catalog=Test;User Id=sa;Password=123;";//
///
/// 执行sql语句
///
/// 需要执行的SQL
/// 对于 UPDATE、INSERT 和 DELETE 语句,返回值为该命令所影响的行数。
///
对于 CREATE TABLE 和 DROP TABLE 语句,返回值为 0。
///
对于所有其他类型的语句,返回值为 -1。
public static int ExcSQL(string sql)
{
SqlConnection Conn = new SqlConnection(strSqlConn);
try
{
Conn.Open();
SqlCommand sqlCmd = new SqlCommand(sql, Conn);
int val = sqlCmd.ExecuteNonQuery();
return val;
}
finally
{
Conn.Close();
Conn.Dispose();
}
}
///
/// 按sql语句返回DataReader
///
///
///
public static SqlDataReader GetDataReader(string sql)
{
try
{
SqlConnection Conn = new SqlConnection(strSqlConn);
SqlCommand SqlCmd = new SqlCommand(sql, Conn);
Conn.Open();
SqlDataReader sqlDr = SqlCmd.Exe