0

users table
userid PK + autoincrement
name
surname

i wrote a procedure

ALTER PROCEDURE insertUser
@userid int,
@name varchar(50),
@surname varchar(50),
AS
	SET NOCOUNT ON
insert into users (userid,name,surname) values (@userid,@name,@surname,)

in aspx file i write

cmd.Parameters.AddWithValue("@userid", ????????);
cmd.Parameters.AddWithValue("@name", TextBox2.Text);
cmd.Parameters.AddWithValue("@surname", TextBox3.Text);

what can i assign for userid column for add with parameters...

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by dnanetwork
0

If the UserId is an auto increment column in the users table then you do not specify a parameter. You simply:

insert into users (name,surname) values (@name,@surname)

After the insert query you can

Select Cast(SCOPE_IDENTITY() as int) As UserId

That will give you the seed value that was just inserted.

0

you just skip this line.

cmd.Parameters.AddWithValue("@userid", ????????);

Because autoincrement columns do not need anything whenever you add a new record.

1

you just skip this line.

cmd.Parameters.AddWithValue("@userid", ????????);

Because autoincrement columns do not need anything whenever you add a new record.

That will still raise an exception because the stored procedure insertUser still references the UserId column in the insert.

You need to remove all references to UserId for inserts

Votes + Comments
thanks for clerification
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.