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?

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

how to insert the data from ASP.NET by using C#

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.