using system;
using system.configuration;
using system.data.sqlclient;
using system.data;
using system.collections;
比如:
// 打开数据库
转自:动态网制作指南 www.knowsky.com
public static sqlconnection openconnection()
{
sqlconnection mysqlconn = new sqlconnection(configurationsettings.appsettings["connstring"]);
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;
}
新闻热点
疑难解答