c#gridview未填充存储过程sql



我正试图用以下代码的存储过程填充网格视图,但实际情况是网格视图没有显示任何内容。

SqlConnection myConnectiona = new SqlConnection("user id=HOME-PC\HOME;" +
                                   "password=password;server=HOME-PC\SQLEXPRESS;" +
                                   "Trusted_Connection=yes;" +
                                   "database=tabrem; " +
                                   "connection timeout=30");
            SqlCommand pro = new SqlCommand("[dbo].[doctor]", myConnectiona);
            pro.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(pro);
            DataTable dt = new DataTable();

        try
        {
                    myConnectiona.Open();
          da.Fill(dt);
          dataGridView1.DataSource = dt;

        }
        catch (Exception w)
        {
            throw;
        }
        finally
        {
            if (myConnectiona.State == ConnectionState.Open)
                myConnectiona.Close();
        }

我认为你需要做(如果这是web表单)

da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.Databind();

感谢

最新更新