Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a stored procedure and when I implement in coding but got an error....

I wrote a code
C#
SqlConnection conn;
           SqlCommand comm;
           string connectionString = ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString;
           conn = new SqlConnection(connectionString);
           comm = new SqlCommand("InsertHelpDesk2", conn);
           comm.CommandType = System.Data.CommandType.StoredProcedure;

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



and in MS-SQL 2008 i wrote

SQL
CREATE PROCEDURE InsertHelpDesk2
(
@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)



error i got is

I am getting error on

C#
comm.ExecuteNonQuery();

Could not find stored procedure 'InsertHelpDesk2'

please tell me where i am wrong
Posted
Updated 13-Nov-11 18:51pm
v4
Comments
Al Moje 14-Nov-11 0:24am    
Hi,
You created InsertHelpDesk1, but in your code behind you are calling
store procedure 'InsertHelpDesk2'. Advise you to review your code...
shivani 2013 14-Nov-11 0:31am    
Sorry, I wrote wrong over here. I have written inserthelpdesk2 only in my code.I am getting same error.

Replace ur code

comm = new SqlCommand("InsertHelpDesk1", conn);
 
Share this answer
 
You have stored procedure by name InsertHelpDesk1 and you gave InsertHelpDesk2 that is why you got the error.
 
Share this answer
 
Comments
shivani 2013 14-Nov-11 0:32am    
Sorry, I wrote wrong over here. I have written inserthelpdesk2 only in my code.I am getting same error.
Hi,

please check stored procedure is exist in database, i think when to create stored procedure, you does not select proper database. so it get created in master database by default.

thanks and Regards,
Nilesh
 
Share this answer
 
Comments
shivani 2013 14-Nov-11 2:18am    
No, I have created this on Dorknozzle1 database
shivani 2013 14-Nov-11 2:34am    
stored procedure is in exist database
hi,

Please check the schema for the storeprocedure. if you create the SP without giving the schema name then by default it takes the the login schema. default schema id "dbo"
 
Share this answer
 
Comments
shivani 2013 15-Nov-11 0:06am    
I am not getting what you are saying.I have made one database named Dorknozzle1 and in that there is a folder Programmability thereand in that there is stored procedure and in that ,"InserrtHelpdesk1" sp exists
[no name] 18-Nov-11 6:22am    
Hi,

Do you know the schema for the SP??

If not then write click on the sp and alter the SP then its shows the code like this
ALTER PROCEDURE [schema].[InsertHelpDesk2]
(..........

that [Schema] use mention in your code
comm = new SqlCommand("Schema.InsertHelpDesk2", conn);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900