SqlConnection conn = null; string conString = "Data Source=; Initial Catalog=資料庫名;User ID=賬戶;Password=密碼";//連接資料庫的字元串 conn = new SqlConnection(conStri ...
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"];