0

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

3
Contributors
4
Replies
6
Views
10 Years
Discussion Span
Last Post by somit
0

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 by pyTony: fixed formatting

0

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?

0

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.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.