头文件添加
using System.Data;
using System.Data.SqlClient;
创建链接
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=服务器ip;database=数据库名;uid=数据库账户;pwd=密码";
con.Open();
写sql语句
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "sql语句";
SqlDataReader dr = com.ExecuteReader();//执行SQL语句
SqlDataReader dx = dr;//执行SQL语句
取数据
while (dr.Read())--类似指针
{ cs5 = String.Format("{0}_{1}_{2}", dr[9], dr[10], dr[11]) }