Hi guys,

This is my first post here. Actually wanted to insert record into an sql database (using sql server 2000 and visual studio 2000)

I'm using a dataview to see if the user already exists. This, i've been able to retrieve and it works.

Now if the user does not exist, then i add the new user using parameter passing.

strInsert = "Insert INTO tbl_user(username,password,firstname,lastname,email,status,dateRegistered,sex,type_id,school_id)Values(@username,@password,@firstname,@lastname,@email,@status,@dateRegistered,@sex,@type_id,@school_id)"
cmdInsertUser = New SqlCommand(strInsert, sqlConn)
            cmdInsertUser.Parameters.Add("@username", txtUsername.Text.ToLower)

...and so on

cmdInsertUser.ExecuteNonQuery()

I'm getting an error in terms of id cannot be null for my user_id. Doesn't it increment by itself? I'm not using stored procedures.

Is there a way to do this (and without stored procedures)?

Thanks for a reply

Dany

Doesn't it increment by itself?

it depends on how that column is setup in the database. Is it set up as an identity column?

Edited 3 Years Ago by pyTony: fixed formatting

Hi,

It is set as a primary key in the database but i still get that error of id cannot be null.

Any reason why this is happening.

Thanks guys.

it depends on how that column is setup in the database. Is it set up as an identity column?

Hi,

Problem solved. It was in my schema- Identity (as you said) was not set.
Thanks for this hint.

Cheers

Dany

This question has already been answered. Start a new discussion instead.