using System;
using SystemConfiguration;
using SystemDataSqlClient;
using SystemData;
using SystemCollections;
比如
// 打开数据库
转自动态网制作指南
public static SqlConnection OpenConnection()
{
SqlConnection mysqlConn = new SqlConnection(ConfigurationSettingsAppSettings[connstring]);
try
{
mysqlConnOpen();
}
catch (Exception e)
{
//rethrow this exception
throw e;
}
return mysqlConn;
}
// 执行SQL返回DataSet
public static DataSet GetDataSet(string SQLQuery)
{
SqlConnection cn = DBObjectOpenConnection();
SqlDataAdapter da = new SqlDataAdapter(SQLQuery cn);
DataSet ds = new DataSet();
daFill(ds);
//release resources
daDispose();
da = null;
cnClose();
cn = null;
return ds;
}
// 执行SQL语句
public static void ExecuteUpdateQuery(string SQLQuery)
{
SqlConnection cn = DBObjectOpenConnection();
SqlCommand cmd = new SqlCommand();
cmdCommandText = SQLQuery;
cmdCommandType = CommandTypeText;
cmdConnection = cn;
cmdExecuteNonQuery();
cnClose();
cn = null;
}