943,962 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 62524
  • ASP.NET RSS
Oct 24th, 2006
0

Insert into sql database

Expand Post »
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.

ASP.NET Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
requiem2 is offline Offline
6 posts
since Jun 2006
Oct 24th, 2006
0

Re: Insert into sql database

Click to Expand / Collapse  Quote originally posted by requiem2 ...
[/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?
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
Oct 25th, 2006
0

Re: Insert into sql database

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.

Click to Expand / Collapse  Quote originally posted by campkev ...
it depends on how that column is setup in the database. Is it set up as an identity column?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
requiem2 is offline Offline
6 posts
since Jun 2006
Oct 29th, 2006
0

Re: Insert into sql database

Hi,

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

Cheers

Dany
Reputation Points: 10
Solved Threads: 0
Newbie Poster
requiem2 is offline Offline
6 posts
since Jun 2006
Jan 16th, 2010
0
Re: Insert into sql database
how to insert the data from ASP.NET by using C#
Reputation Points: 10
Solved Threads: 0
Newbie Poster
somit is offline Offline
1 posts
since Jan 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in ASP.NET Forum Timeline: dynamic page insertion
Next Thread in ASP.NET Forum Timeline: how to update drop down boxes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC