i have create database with tables using sql server 2008, having table named 'Users'
i have create this stored procedure :
/****** Object: StoredProcedure [dbo].[InsertUser] Script Date: 02/17/2013 23:25:06 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE PROCEDURE [dbo].[InsertUser]
@ID int ,
SET NOCOUNT ON
INSERT INTO dbo.Users
then i used it inside C# Visual Studio 2010 to execute stored procedure with this code :
Try executing the stored procedure in SQL Studio and see if it gives you the same result.
It could be that;
A) You created the Users table on a different schema to dbo. (Kind of unlikely because you'd know about it...)
B) Your SQL connection string hasn't selected an initial database to use and is connected to 'master' by default.
C) Try using [dbo].[Users]. It shouldn't make a difference but consistency doesn't hurt.
To have using statements is better but not necessary. Also I presume you meant to include your connection in the using statement? The OP would also be able to put the SqlCommand into another using statement.
ExecuteScalar is unnecessary because his procedure returns no values.
ExecuteScalar is used when you return a single value from your procedure. You can typically use this to return things such as the row identity if you're inserting or an aggregate value or something along those lines.
ExecuteNonQuery is used when you have nothing to return from the procedure. What you get as the result is the number of rows affected by your query. Importantly, you can use ExecuteNonQuery when you expect OUTPUT parameters, but no specific return value. Like a void method that takes a ref parameter argument.