954,184 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Insert into sql database

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

requiem2
Newbie Poster
6 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 
[/code] 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?

campkev
Posting Pro in Training
484 posts since Jul 2005
Reputation Points: 14
Solved Threads: 19
 

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?

requiem2
Newbie Poster
6 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

Hi,

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

Cheers

Dany

requiem2
Newbie Poster
6 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

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

somit
Newbie Poster
1 post since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You