用SqlConnection连接SQL Server数据库
//引用
using Dystem.Data.SqlClient;string conString="data source=ip地址;initial catalog=数据库名称;user id=用户名;password=密码;persist security info=True";
//string conString="datasource=ip地址;database=数据库名称;user id=用户名;password=密码";
SqlConnection myconn=new SqlConnection(conString);
#regsion取数据集
string strSql="SELECT * FROM 表名";
myconn.open();
SqlDataAdapter dap=new SqlDataAdapter(strSql,myconn);
//返回DataSet
DataSet ds=new DataSet();
dap.Fill(ds);
//返回datatable
//DataTable dt=new DataTable();
//dap.Fill(dt);
#endregsion
//#regsion取单一值
//string strSql="SELECT 某字段单一值 FROM TABLE";
//SqlCommand com=new SqlCommond(strSql,myconn);
//object objFieldValue=com.ExecuteScalar();
//string strFieldValue=objFieldValue.ToString();
//#endregsion
myconn.Dispose();
myconn.Close();