C# dataGridView展示数据库查询结果

C# dataGridView展示数据库查询结果

        private void browsetc()
        {
     
            //SqlConnection cn = new SqlConnection(sqlText.sql);
            login frmlg = new login();
            string urlIP = "Data Source =" + frmlg.textIP.Text.Trim() + sqlText.sql;
            SqlConnection cn = new SqlConnection(urlIP);
            cn.Open();

            string sql = @"SELECT * FROM [tc_2020]  where Status = 0";//
            SqlCommand cmd = new SqlCommand(sql, cn);

            SqlDataAdapter da = new SqlDataAdapter();

            da.SelectCommand = cmd;

            DataSet ds = new DataSet();

            da.Fill(ds);

            cn.Close();
            //dataGridView2.DataSource = ds.Tables[0];
            dataGridView2.DataSource = ds.Tables[0];
            //dataGridView行数统计
            label20.Text = dataGridView2.Rows.Count.ToString();

            
        }

你可能感兴趣的