//--1 string ConStr = "Persist Security Info=False;Initial Catalog=northwind(这个事数据库名,也可以写成database=northwind);"; ConStr += @"Data Source=.(或者.\sqlexpress主要看你SQL SERVER是哪个版本的);Integrated Security=SSPI;(是否开启WINDOWS验证SSPI或者TRUE表示是)"; SqlConnection myCon = new SqlConnection(ConStr); string ComStr = "select * from employees"; SqlCommand myCom = new SqlCommand(ComStr, myCon); SqlDataAdapter myDA = new SqlDataAdapter(); myDA.SelectCommand = myCom; myCon.Open(); DataSet myDS = new DataSet(); myDA.Fill(myDS, "employees"); //----2 string cmdtxt1 = @"Data Source=localhost\sqlexpress;database=Northwind;Uid=sa;Pwd=sa"; string cmdtxt2 = "SELECT CustomerID,CompanyName,ContactName,ContactTitle FROM Customers"; SqlConnection Con = new SqlConnection(cmdtxt1); Con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmdtxt2, Con); DataSet ds = new DataSet(); da.Fill(ds); 建议楼主去买本数据库的书看下。如果连最简单的连接都不知道的话。真要非常需要买本讲数据库的书好好的看下。
string str = "Server=.;User=sa;PWD=000;DataBase=test";// SqlConnection conn = new SqlConnection(str); SqlDataAdapter pos = new SqlDataAdapter("select leftpole as '左柱',rightpole as '右柱',time as '时间' from stress", conn); DataSet dspos = new DataSet(); pos.Fill(dspos, "tables"); this.dataGridView1.DataSource = dspos.Tables["tables"]; 希望能看懂,没有时间写注释
eg:server=127.0.0.1,database=test,uid=sa,pwd=test
然后按照向导去配置数据库连接就可以了。
//--1
string ConStr = "Persist Security Info=False;Initial Catalog=northwind(这个事数据库名,也可以写成database=northwind);";
ConStr += @"Data Source=.(或者.\sqlexpress主要看你SQL SERVER是哪个版本的);Integrated Security=SSPI;(是否开启WINDOWS验证SSPI或者TRUE表示是)";
SqlConnection myCon = new SqlConnection(ConStr);
string ComStr = "select * from employees";
SqlCommand myCom = new SqlCommand(ComStr, myCon);
SqlDataAdapter myDA = new SqlDataAdapter();
myDA.SelectCommand = myCom;
myCon.Open();
DataSet myDS = new DataSet();
myDA.Fill(myDS, "employees");
//----2
string cmdtxt1 = @"Data Source=localhost\sqlexpress;database=Northwind;Uid=sa;Pwd=sa";
string cmdtxt2 = "SELECT CustomerID,CompanyName,ContactName,ContactTitle FROM Customers";
SqlConnection Con = new SqlConnection(cmdtxt1);
Con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmdtxt2, Con);
DataSet ds = new DataSet();
da.Fill(ds);
建议楼主去买本数据库的书看下。如果连最简单的连接都不知道的话。真要非常需要买本讲数据库的书好好的看下。
SqlConnection conn = new SqlConnection(str);
SqlDataAdapter pos = new SqlDataAdapter("select leftpole as '左柱',rightpole as '右柱',time as '时间' from stress", conn);
DataSet dspos = new DataSet();
pos.Fill(dspos, "tables");
this.dataGridView1.DataSource = dspos.Tables["tables"];
希望能看懂,没有时间写注释