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"];

 

posted @ 2020-03-13 19:39  越吃越瘦  阅读(466)  评论(0编辑  收藏  举报