Insert into sql database

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2006
Posts: 6
Reputation: requiem2 is an unknown quantity at this point 
Solved Threads: 0
requiem2 requiem2 is offline Offline
Newbie Poster

Insert into sql database

 
0
  #1
Oct 24th, 2006
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.

  1. 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)"
  2. cmdInsertUser = New SqlCommand(strInsert, sqlConn)
  3. cmdInsertUser.Parameters.Add("@username", txtUsername.Text.ToLower)
  4.  
  5. ...and so on
  6.  
  7. 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
Last edited by requiem2; Oct 24th, 2006 at 11:36 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Insert into sql database

 
0
  #2
Oct 24th, 2006
Originally Posted by requiem2 View Post
[/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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 6
Reputation: requiem2 is an unknown quantity at this point 
Solved Threads: 0
requiem2 requiem2 is offline Offline
Newbie Poster

Re: Insert into sql database

 
0
  #3
Oct 25th, 2006
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.

Originally Posted by campkev View Post
it depends on how that column is setup in the database. Is it set up as an identity column?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 6
Reputation: requiem2 is an unknown quantity at this point 
Solved Threads: 0
requiem2 requiem2 is offline Offline
Newbie Poster

Re: Insert into sql database

 
0
  #4
Oct 29th, 2006
Hi,

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

Cheers

Dany
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC