可以转载,转载请著名作者和出处,谢谢,特别鄙视转载后扣上自己名字的哥们
using System;
using System.Data;
using System.Data.SqlClient;
namespace ShineMembers
{
///
/// SQL_Management 的摘要说明。
///
public class SQL_Management
{
string _connString = null;
SqlConnection _conn;
public SQL_Management()
{
}
public void SetConnection(string Uid,string Pw,string Catelog,string Server)
{
_connString = "Initial Catalog=" + Catelog + ";Data Source=" +
Server + ";User ID=" + Uid + ";password=" + Pw;
try
{
_conn = new SqlConnection(_connString);
_conn.Open();
}
catch(Exception exp)
{
throw exp;
}
}
public SqlConnection GetConnection()
{
if (_conn.Equals(null))
{
throw new Exception();
}
else
return _conn;
}
public DataSet GetDataSet(string strSql)
{
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(strSql,_conn);
adapter.Fill(ds);
return ds;
}
public DataSet GetDataSet(string strSql,string strTable)
{
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(strSql,_conn);
adapter.Fill(ds,strTable);
return ds;
}
public DataTable GetDataTable(string strSql)
{
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(strSql,_conn);
adapter.Fill(dt);
return dt;
}
public object GetDataReader_Scale(string strSql)
{
SqlCommand cmd = new SqlCommand(strSql,_conn);
try
{
return cmd.ExecuteScalar();
}
catch(Exception exp)
{
throw exp;
}
}
}
}
阅读(1188) | 评论(0) | 转发(0) |