using System;
using System.Configuration;
using System.Data.SqlClIEnt;
using System.Data;
using System.Collections;
比如:
// 打開數據庫
try
{
MySQLConn.Open();
}
catch (Exception e)
{
//rethrow this exception
throw e;
}
return MySQLConn;
}
// 執行SQL返回DataSet
public static DataSet GetDataSet(string SQLQuery)
{
SqlConnection cn = DBObject.OpenConnection();
SqlDataAdapter da = new SqlDataAdapter(SQLQuery, cn);
DataSet ds = new DataSet();
da.Fill(ds);
//release resources
da.Dispose();
da = null;
cn.Close();
cn = null;
return ds;
}
// 執行SQL語句
public static void ExecuteUpdateQuery(string SQLQuery)
{
SqlConnection cn = DBObject.OpenConnection();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = SQLQuery;
cmd.CommandType = CommandType.Text;
cmd.Connection = cn;
cmd.ExecuteNonQuery();
cn.Close();
cn = null;
}