Click here to Skip to main content
15,884,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to get the last row in a column using C# however when I run my code it returns a null value, when I run the same code in sql-server I get the result I am looking for. here is the c# line I am using to extract the data.

C#
SqlCommand com = new SqlCommand("Select TOP 1[Window Title] FROM [TimerLogs]", Conn);

and the code I use in sql-server

SQL
SELECT Top 1[Window Title]
    
  FROM [Log Records].[dbo].[TimerLogs]
GO

However I do not get a result in my c# application.
Posted
Updated 16-Jun-14 23:45pm
v2

Select TOP (1)[Window Title] FROM [TimerLogs] order by 1 desc
 
Share this answer
 
v3
Comments
Eon Kusanagi 17-Jun-14 5:47am    
I made a slight mistake with the code I put there I did not have the top 1 in it. I had been trying something different basically i wanted to test if it was pulling any data without the top 1 function that is why it did not have top 1. Adding top 1 in the query gave me an error in the way you suggested
agent_kruger 17-Jun-14 5:50am    
sir, can you tell us what error it prompted.
Eon Kusanagi 17-Jun-14 5:53am    
well with the code he suggested I get an "incorrect syntax used near top 1" and with my own code I get no error however it does not pull any data from the database
wladimirbm 17-Jun-14 6:09am    
try use top(1)
Eon Kusanagi 17-Jun-14 7:04am    
I tried that as well could it be possible that I am using the code incorrectly
SQL
Select TOP 1 [Window Title] FROM [TimerLogs] Order By 1 Desc
 
Share this answer
 
Comments
Eon Kusanagi 17-Jun-14 6:46am    
I am still getting a null result

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900