C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 307,089 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,054 people online right now. Registration is fast and FREE... Join Now!




Item Number and SQL?

 

Item Number and SQL?

Mowgef

30 Jun, 2009 - 10:44 AM
Post #1

D.I.C Head
**

Joined: 1 May, 2009
Posts: 236



Thanked: 10 times
My Contributions
Hi, I need an opinion on something. I'm working on a website and we have a function to open a new job listing.

I need a way to for each new job listing to have its own id number. I was thinking an ascending list, by getting the latest one used and adding one to it but that seems iffy. I don't want conflicts in ID numbers because the code moves too slow.

But could that be a problem? Are there any other ways I can do this?

I guess I could have the insert in a try block and if it fails, add one again and try reinserting.

This post has been edited by Mowgef: 30 Jun, 2009 - 10:48 AM

User is offlineProfile CardPM
+Quote Post


modi123_1

RE: Item Number And SQL?

30 Jun, 2009 - 11:21 AM
Post #2

Suiter #2
Group Icon

Joined: 12 Jun, 2008
Posts: 1,835



Thanked: 80 times
Dream Kudos: 150
My Contributions
Is this being stored on a database? The auto increment for your key column works fine.
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo

RE: Item Number And SQL?

30 Jun, 2009 - 11:21 AM
Post #3

Not Your Ordinary Programmer
Group Icon

Joined: 21 Mar, 2008
Posts: 1,846



Thanked: 205 times
Dream Kudos: 500
Expert In: .NET

My Contributions
are you using a database of some kind to store the job listings? if not, how are you saving the job listings?
User is offlineProfile CardPM
+Quote Post

Mowgef

RE: Item Number And SQL?

30 Jun, 2009 - 11:36 AM
Post #4

D.I.C Head
**

Joined: 1 May, 2009
Posts: 236



Thanked: 10 times
My Contributions
yeah sorry I'm using a database, thought I typed that...oops

Yes, the number id would be stored in the table.
User is offlineProfile CardPM
+Quote Post

baavgai

RE: Item Number And SQL?

30 Jun, 2009 - 11:57 AM
Post #5

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 4,349



Thanked: 411 times
Dream Kudos: 550
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
To be clear, most databases have mechanism to create columns with automatic counters. If you're doing C#, you'll probably want SQL Server.

Here's an example:
CODE

create table test ( test_id int identity(1,1), txt varchar(30));

insert into test(txt) values('Sis')
insert into test(txt) values('Bah')
insert into test(txt) values('Boom')
insert into test(txt) values('Sheep Exploded')

select * from test


Results:
CODE

test_id     txt
----------- ------------------------------
1           Sis
2           Bah
3           Boom
4           Sheep Exploded


User is online!Profile CardPM
+Quote Post

Mowgef

RE: Item Number And SQL?

30 Jun, 2009 - 12:17 PM
Post #6

D.I.C Head
**

Joined: 1 May, 2009
Posts: 236



Thanked: 10 times
My Contributions
thanks baav, I had no idea about Identity. exactly what I needed. smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 11:22AM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month