从ASP.Net执行存储过程3.5

问题描述:

我需要通过前缀一个系统过程帮助..从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 

我得到的结果是否正确 有什么建议? 在此先感谢..

你预先考虑,因此附加一个单引号的错误。数据库名称不需要引号。

尝试:

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

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();