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...

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.

you just skip this line.

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

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

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

commented: thanks for clerification +1

keep the Column as AutoNubmber / ScopeIdentity() is the best option while inserting..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.