Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Selecting a specific row

Author  Topic 

gayamantra
Starting Member

5 Posts

Posted - 2004-08-21 : 23:02:03
Hi,

I need to select a particular row from a result set. Like selecting the 2nd row from a resulting set of 10 rows...what would the syntax be? Thanks in advance..

Gayathri

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-08-22 : 02:34:10
Depends on how they're sorted I suppose.
It should be possible, but can you give some background on what you're trying to do?
Go to Top of Page

gayamantra
Starting Member

5 Posts

Posted - 2004-08-22 : 04:26:15
Hi again,

My query is such
Select linkURL from tblAllLinks where linkFoundOn='achievements.asp'

The query returns more than one result i.e abt 3 rows.

I need to channel each of this result into a html hyperlink on my webpage. I was thinking this way..but dunno whether possible.

string SelectQuery="Select linkURL from tblAllLinks where linkFoundOn='achievements.asp'";
SqlCommand cmd = new SqlCommand(SelectQuery, con);
SqlDataReader dtr = cmd.ExecuteReader();

dtr.Read();

achievements.NavigateUrl =dtr[0].ToString() ;
news.NavigateUrl =dtr[1].ToString() ;

con.Close();

}

But then i get the error 'Index was outside the bounds of the array'.

Pls advise.

Gayathri

Go to Top of Page

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-08-22 : 07:02:27
You need to use:
news.NavigateUrl =dtr[0].ToString() ;

because there is only one item in the array
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-08-22 : 07:38:29
dtr.Read();
achievements.NavigateUrl =dtr[0].ToString() ;
dtr.Read();
news.NavigateUrl =dtr[0].ToString() ;


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

gayamantra
Starting Member

5 Posts

Posted - 2004-08-22 : 07:39:56
The result of the query returns more than one row. I understand i that the '0' in the dtr array means the COLUMN but what if i want to access each ROW separately??
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-22 : 07:52:08
and

while (dtr.Read())
{
// do stuff with data...
}

doesn't work for you?



Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -