如何使用存储过程删除错误? [英] How to remove an error using Stored Procedure?

查看:63
本文介绍了如何使用存储过程删除错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个存储过程,当我实现编码时遇到了错误....

我写了一个代码


I have created a stored procedure and when I implement in coding but got an error....

I wrote a code


SqlConnection conn;
            SqlCommand comm;
            string connectionString = ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString;
            conn = new SqlConnection(connectionString);
            comm = new SqlCommand("InsertHelpDesk1", conn);
            comm.CommandType = System.Data.CommandType.StoredProcedure;


comm.Parameters.Add("@EmployeeID", System.Data.SqlDbType.Int,50);
           comm.Parameters["@EmployeeID"].Value = 5;
           comm.Parameters.Add("@StationNumber", System.Data.SqlDbType.Int);
           comm.Parameters["@StationNumber"].Value = stationTextBox.Text;
           comm.Parameters.Add("@CategoryID", System.Data.SqlDbType.Int);
           comm.Parameters["@CategoryID"].Value = categorylist.SelectedItem.Value;
           comm.Parameters.Add("@SubjectID", System.Data.SqlDbType.Int);
           comm.Parameters["@SubjectID"].Value = subjectlist.SelectedItem.Value;
           comm.Parameters.Add("@Description", System.Data.SqlDbType.NVarChar, 50);
           comm.Parameters["@Description"].Value = descriptionTextBox.Text;
           comm.Parameters.Add("@StatusID", System.Data.SqlDbType.Int);
           comm.Parameters["@StatusID"].Value = 1;
      
               conn.Open();
               comm.ExecuteNonQuery();
               Response.Redirect("HelpDesk.aspx");
          
  conn.Close();


在MS-SQL 2008中我写了



and in MS-SQL 2008 i wrote


CREATE PROCEDURE InsertHelpDesk1
(
@EmployeeID int,
@StationNumber int,
@CategoryID int,
@SubjectID int,
@Description nvarchar(50),
@StatusID int
)
AS
INSERT INTO Dorknozzle1.dbo.HelpDesk1 (EmployeeID, StationNumber, CategoryID,
SubjectID, Description, StatusID)
VALUES (@EmployeeID, @StationNumber, @CategoryID, @SubjectID,
@Description, @StatusID)



这里的Helpdesk1是表名

我在
上出错



Here Helpdesk1 is table name

I am getting error on

comm.ExecuteNonQuery();


我得到的错误是

找不到存储过程"InsertHelpDesk1"

请告诉我我在想什么
感谢和问候


and error i got is

Could not find stored procedure ''InsertHelpDesk1''

please tell me what i am missing
Thanx and regards

推荐答案

使用
comm = new SqlCommand("dbo.InsertHelpDesk1", conn);



还要检查过程的模式名称.如果不是dbo,则需要将其更改为dbo.让我知道会发生什么

[edit]我知道这只是一个衬里,但是请格式化所有代码块-这是一个很好的习惯,因此您不要忘记多行代码



Also check the schema name of procedure . If its not dbo then you need to change it to dbo. Let me know what happens

[edit] I know it is only a one liner, but please format all code blocks - it is a good habit to get into so you don''t forget on mulitlined code


提起SQL Server Management Studio,并检查是否执行了存储过程插入代码:即该过程是否确实存在于您通过连接字符串引用的数据库中.

错误消息非常明显:该过程不存在.您可能没有创建它,或者您已经在其他数据库中创建了它.
Bring up SQL Server Management Studio, and check that you executed the stored procedure insert code: i.e. that the procedure exists in exactly the database you are referencing via your connection string.

The error message is quite explicit: the procedure is not there. Either you didn''t cretae it, or you have created it in a different database.


I checked ur code.. It insert without any errors
Please check your Database whether the stored procedure is available
I checked ur code.. It insert without any errors
Please check your Database whether the stored procedure is available
Please check your web config file whether u have mention the database name<br />
properly



问候
Prince Antony



Regards
Prince Antony


这篇关于如何使用存储过程删除错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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