本文介绍了找不到存储过程'procedurename'错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为storedproceed的存储过程。我在类文件中完成的代码如下:

  public   class  Class1 
{
private int _Event;
private int _EmpId;
private string _EmpName;
private int _Salary;
private string _City;
private int _Atype;

public int 活动
{
get { return _Event; }
set {Event = value ; }
}
public int EmpId
{
get { return _EmpId; }
set {_EmpId = value ; }
}
public string EmpName
{
get { return _EmpName; }
set {_EmpName = value ; }
}
public int 薪水
{
get { return _Salary; }
set {_Salary = value ; }
}
public string 城市
{
get { return _City; }
set {_City = value ; }
}
public int Atype
{
get { return _Atype; }
set {_Atype = value ; }
}
public void save()
{
字符串 constr = ConfigurationManager.ConnectionStrings [ TestConnectionString ]的ConnectionString。
SqlConnection connect = new SqlConnection(constr);
SqlCommand command = new SqlCommand( spAllinone ,连接);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add( @ event,SqlDbType.TinyInt).Value =一种;
command.Parameters.Add( @ EmpId,SqlDbType.Int).Value = EmpId;
command.Parameters.Add( @ Emp_name,SqlDbType.NVarChar, 50 )。Value = EmpName;
command.Parameters.Add( @ Salary,SqlDbType.Int).Value =薪水;
command.Parameters.Add( @ City,SqlDbType.NVarChar, 50 )。值=城市;
connect.Open();
command.ExecuteNonQuery();
command.Connection.Close();



我的.cs文件中的代码我是:

 受保护  void  Button1_Click( object  sender,EventArgs e)
{
Class1 obj = new Class1();
obj.EmpId = Convert.ToInt32(txtEmpId.Text);
obj.EmpName = txtEmpName.Text;
obj.Salary = Convert.ToInt32(txtSalary.Text);
obj.City = txtCity.Text;
obj.Atype = Convert.ToInt32(txtEvent.Text);
obj.save();



当我调试我的程序时问题是什么它给出了错误,即找不到存储过程。为什么?甚至我检查它存在于数据库中。

解决方案



i have created a stored procedure named storedproceed. the code i done in class file is as :

public class Class1
{
    private int _Event;
    private int _EmpId;
    private string _EmpName;
    private int _Salary;
    private string _City;
    private int _Atype;

    public int Event
    {
        get { return _Event; }
        set { Event = value; }
    }
    public int EmpId
    {
        get { return _EmpId; }
        set { _EmpId = value; }
    }
    public string EmpName
    {
        get { return _EmpName; }
        set { _EmpName = value; }
    }
    public int Salary
    {
        get { return _Salary; }
        set { _Salary = value; }
    }
    public string City
    {
        get { return _City; }
        set { _City = value; }
    }
    public int Atype
    {
        get { return _Atype; }
        set { _Atype = value; }
    }
	public void save()
	{
        String constr = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
        SqlConnection connect = new SqlConnection(constr);
        SqlCommand command = new SqlCommand("spAllinone", connect);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add("@event", SqlDbType.TinyInt).Value = Atype;
        command.Parameters.Add("@EmpId", SqlDbType.Int).Value = EmpId ;
        command.Parameters.Add("@Emp_name", SqlDbType.NVarChar,50).Value = EmpName ;
        command.Parameters.Add("@Salary", SqlDbType.Int).Value = Salary ;
        command.Parameters.Add("@City", SqlDbType.NVarChar,50).Value = City ;
        connect.Open();
        command.ExecuteNonQuery();
        command.Connection.Close();


the code in my .cs file i as :

protected void Button1_Click(object sender, EventArgs e)
{
    Class1 obj = new Class1();
   obj.EmpId = Convert.ToInt32(txtEmpId.Text);
    obj.EmpName = txtEmpName.Text;
    obj.Salary = Convert.ToInt32(txtSalary.Text);
    obj.City = txtCity.Text;
    obj.Atype = Convert.ToInt32(txtEvent.Text);
    obj.save();


what the problem is when i debug my program it gives error that stored procedure is not found.why?even i check it is present in database.

解决方案



这篇关于找不到存储过程'procedurename'错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 23:03