SQL连接数据库
SqlConnection conn = null; string conString = "Data Source=; Initial Catalog=数据库名;User ID=账户;Password=密码";//连接数据库的字符串 conn = new SqlConnection(conString); conn.Open();//打开数据库连接 if (conn.State == ConnectionState.Open) { // Console.WriteLine("数据库连接成功"); } string sql = "SELECT * FROM LE_Calibration WHERE mo='M0PWP2SMA01001'"; SqlDataAdapter da = new SqlDataAdapter(sql, conn);//从数据库中查询 conn.Close(); DataSet ds = new DataSet(); da.Fill(ds, "product");//将数据填充到DataSet DataTable myTable = ds.Tables["product"];