2011-08-04 41 views
0

我需要通過前綴一個系統過程幫助..從ASP.Net執行存儲過程3.5

exec [your database name]..sp_tables 

在這裏,在上面的代碼中的[數據庫名稱]應該是一個文本框的值 這裏是我的代碼..

string DatabaseName = txtbox.Text; 
     using (SqlDataAdapter sda = new SqlDataAdapter("exec ['"+DatabaseName+"']..sp_tables", conn)) 
     { 
      DataSet ds = new DataSet(); 
      sda.Fill(ds); 
      DropDownList2.DataTextField = "TABLE_NAME"; 
      DropDownList2.DataSource = ds; 
      DropDownList2.DataBind(); 
     } 

我收到錯誤

Database '.net'' does not exist. Make sure that the name is entered correctly. 

當我執行

exec [.net]..sp_tables 

我得到的結果是否正確 有什麼建議? 在此先感謝..

回答

0

你預先考慮,因此附加一個單引號的錯誤。數據庫名稱不需要引號。

嘗試:

new SqlDataAdapter("exec ["+DatabaseName+"]..sp_tables", conn))

0
exec [your database name]..sp_tables 

Here in above code the [your database name] should be a textbox value here is my code.. 

string DatabaseName = txtbox.Text; 
     using (SqlDataAdapter sda = new SqlDataAdapter("exec ["+DatabaseName+"]..sp_tables", conn)) 
     { 
      DataSet ds = new DataSet(); 
      sda.Fill(ds); 
      DropDownList2.DataTextField = "TABLE_NAME"; 
      DropDownList2.DataSource = ds; 
      DropDownList2.DataBind();