Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,685 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,250 people online right now. Registration is fast and FREE... Join Now!




using select statement to grab index of item in sql database

2 Pages V  1 2 >  
Reply to this topicStart new topic

using select statement to grab index of item in sql database, not sure if this belongs here

rgfirefly24
post 27 May, 2008 - 11:36 AM
Post #1


D.I.C Regular

Group Icon
Joined: 7 Apr, 2008
Posts: 330



Thanked 5 times

Dream Kudos: 150
My Contributions


ok so here is the situation:

I have a Table of countries (238 + Please Select Country) what i need is to be able to get the index of the Please Select Country using a select statement in C#. i've tried getting row num:

CODE

SELECT ROW_NUM() FROM dbo.TableName WHERE Country_Code = '0';// 0 is the value set for Please_Select_Country)


any suggestions on the correct command?
User is offlineProfile CardPM

Go to the top of the page

zakary
post 27 May, 2008 - 11:56 AM
Post #2


D.I.C Regular

Group Icon
Joined: 15 Feb, 2005
Posts: 401



Thanked 6 times

Dream Kudos: 175
My Contributions



csharp

SELECT ROW_NUM FROM dbo.TableName WHERE Country_Code = '0';//

User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 27 May, 2008 - 01:07 PM
Post #3


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


If CountryCode is an INT data type there is no need for the single quotes


sql

SELECT ROW_NUM FROM dbo.TableName WHERE Country_Code = 0
User is offlineProfile CardPM

Go to the top of the page

rgfirefly24
post 27 May, 2008 - 01:23 PM
Post #4


D.I.C Regular

Group Icon
Joined: 7 Apr, 2008
Posts: 330



Thanked 5 times

Dream Kudos: 150
My Contributions


QUOTE(PsychoCoder @ 27 May, 2008 - 02:07 PM) *

If CountryCode is an INT data type there is no need for the single quotes


sql

SELECT ROW_NUM FROM dbo.TableName WHERE Country_Code = 0




ahh, see i knew i was at least on the right track. All the examples i saw of ROW_NUM had it like i do. I'll fix it tomorrow when i get back to work. Thanks guys smile.gif
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 27 May, 2008 - 01:38 PM
Post #5


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


No problem glad we could help. Now tell all your friends about us or I will stalk you until you do tongue.gif
User is offlineProfile CardPM

Go to the top of the page

rgfirefly24
post 28 May, 2008 - 05:05 AM
Post #6


D.I.C Regular

Group Icon
Joined: 7 Apr, 2008
Posts: 330



Thanked 5 times

Dream Kudos: 150
My Contributions


QUOTE(PsychoCoder @ 27 May, 2008 - 02:38 PM) *

No problem glad we could help. Now tell all your friends about us or I will stalk you until you do tongue.gif


lol well i tell everyone I'm able to. You guys are like my super secret Code ninjas.
User is offlineProfile CardPM

Go to the top of the page

rgfirefly24
post 28 May, 2008 - 07:16 AM
Post #7


D.I.C Regular

Group Icon
Joined: 7 Apr, 2008
Posts: 330



Thanked 5 times

Dream Kudos: 150
My Contributions


QUOTE(rgfirefly24 @ 28 May, 2008 - 06:05 AM) *

QUOTE(PsychoCoder @ 27 May, 2008 - 02:38 PM) *

No problem glad we could help. Now tell all your friends about us or I will stalk you until you do tongue.gif


lol well i tell everyone I'm able to. You guys are like my super secret Code ninjas.



now its coming back and yelling at me saying that ROW_NUM is not a valid colum name....... wonder if this is a SQL Server issue

to combat this i just created a PK column named ROW_NUM. Now its wierd that websites would say that you can use ROW_NUM to get the index number of an item in a database, but when used it shot back at me saying it wasn't a valid column name.

This post has been edited by rgfirefly24: 28 May, 2008 - 07:38 AM
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 28 May, 2008 - 07:25 AM
Post #8


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


You're getting that error because that table doesn't contain a column named ROW_NUM
User is offlineProfile CardPM

Go to the top of the page

rgfirefly24
post 28 May, 2008 - 07:40 AM
Post #9


D.I.C Regular

Group Icon
Joined: 7 Apr, 2008
Posts: 330



Thanked 5 times

Dream Kudos: 150
My Contributions


QUOTE(PsychoCoder @ 28 May, 2008 - 08:25 AM) *

You're getting that error because that table doesn't contain a column named ROW_NUM


aye, see edit above smile.gif, From what i've read though ROW_NUM() is a t-SQL or SQL function that returns an int value from 0-infinate based on what row it found the data in the WHERE clause.
User is offlineProfile CardPM

Go to the top of the page

baavgai
post 28 May, 2008 - 08:06 AM
Post #10


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,967



Thanked 96 times

Dream Kudos: 475

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


What is the primary key of your table? That's presumably what you should be selecting for.
User is offlineProfile CardPM

Go to the top of the page

Jayman
post 28 May, 2008 - 08:08 AM
Post #11


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,839



Thanked 38 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


QUOTE(rgfirefly24 @ 28 May, 2008 - 08:40 AM) *

aye, see edit above smile.gif, From what i've read though ROW_NUM() is a t-SQL or SQL function that returns an int value from 0-infinate based on what row it found the data in the WHERE clause.



Which version of Sql Sever are you using?

This is only available in 2005 and later versions.
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 28 May, 2008 - 08:14 AM
Post #12


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


ROW_NUM() is a built in function in Oracle, not MSSQL. For MSSQL look into the ROW_NUMBER function in Transact-SQL smile.gif
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:12AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month