system.data.dll中发生了'system.data.sqlclient.sqlexception'类型的异常,但未在用户代码中处理其他信息:找不到存储过程'spconti'。 [英] An exception of type 'system.data.sqlclient.sqlexception' occurred in system.data.dll but was not handled in user code additional information: could not find stored procedure 'spconti'.

查看:80
本文介绍了system.data.dll中发生了'system.data.sqlclient.sqlexception'类型的异常,但未在用户代码中处理其他信息:找不到存储过程'spconti'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Create Procedure SpConti 
as
Begin
    Select ContinentID,ContitnentName From [SampleDemo].[dbo].tableContinents
End
--****************************
Create Procedure SpGetCountryByContitnentID 1
@ContinentID int 
as
Begin
    Select CountryId,CountryName From [SampleDemo].[dbo].[tableCountries]
	Where [ContinentId]= @ContinentID
End
--****************************
Create Procedure SpGetCityByCountryID 2
@ContryID int 
as
Begin
    Select [CityId],[CityName] From [SampleDemo].[dbo].[tblCities]
	Where [CountryId]= @ContryID
End





C#





C#

protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              ddlContinent.DataSource = GetData("SpConti", null);
              ddlContinent.DataBind();
          }
      }
      private DataSet GetData(string SPname, SqlParameter SPParameter)
      {
          string CS = ConfigurationManager.ConnectionStrings["SampleDemoConnectionString"].ConnectionString;
          SqlConnection conn = new SqlConnection(CS);
          SqlDataAdapter da = new SqlDataAdapter(SPname,conn);
          da.SelectCommand.CommandType = CommandType.StoredProcedure;
          if (SPParameter!=null)
          {
              da.SelectCommand.Parameters.Add(SPParameter);
          }

          DataSet DS = new DataSet();
          da.Fill(DS);
          return DS;
      }





我的尝试:



我在行da.fill(DS)上收到错误-----错误=** System.Data.dll中发生类型'System.Data.SqlClient.SqlException'的异常但是未在用户代码中处理



附加信息:找不到存储过程'SpConti'。**我试图修改第一个存储过程SpConti



What I have tried:

I am getting error on line da.fill(DS)----- Error= "**An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: Could not find stored procedure 'SpConti'.**" me trying to to pring first stored procedure SpConti

推荐答案

您好,



尝试更改以下代码。



Hi,

Try changing your code like the following.

private DataSet GetData(string SPname, SqlParameter SPParameter)
      {
          	string CS = ConfigurationManager.ConnectionStrings["SampleDemoConnectionString"].ConnectionString;
          	SqlConnection conn = new SqlConnection(CS);


                SqlCommand cmd = new SqlCommand("SPname", conn);
		if (SPParameter!=null)
          	{
              		cmd.Parameters.Add(SPParameter);
          	}
                
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                
 
          	DataSet DS = new DataSet();
          	da.Fill(DS);
          	return DS;
      }





在此之前,请确保您的sp存在于数据库中。



谢谢,

Sisir Patro



Prior to this make sure that your sp exists in the database.

Thanks,
Sisir Patro


这篇关于system.data.dll中发生了'system.data.sqlclient.sqlexception'类型的异常,但未在用户代码中处理其他信息:找不到存储过程'spconti'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆