2016-03-29 87 views
0

我想用下面的代碼填充存儲過程的gridview,但最新發生的是gridview沒有顯示任何東西。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(); 
     } 
+1

如果你手動運行它的SP返回的東西嗎? – ChrisBint

+1

如果你在這一行刪除一個斷點:'da.Fill(dt);',你能看到你的結果集嗎? –

回答

1

我認爲你需要做的(如果這是網頁形式)

​​

感謝

+0

這不是網頁表單 –