2016-11-04 90 views
0

我的C#代碼以下部分SQL LAST()函數

cmd = new SqlCommand("SELECT TOP 1 * FROM "+label7.Text+" ORDER BY searches DESC ", con); 
var columnSize = cmd.ExecuteScalar(); 
int plithos = int.Parse(string.Format("{0}", columnSize)); 

哪裏con是我的連接字符串。我想要做的就是把plithossearches的最後一個值。 searches列有超過17條記錄,但由於某種原因,plithos獲得列搜索的第九條記錄,並且該代碼部分不假定記錄最後一條記錄的值?我正在構建的應用程序是Visual Studio中的表單應用程序。請幫助我,這是如此令人沮喪

這裏是列searches

Searches| 1 2 3 4 5 6 7 8 9-> value of plithos . . . 19

+0

你獲取使用多列'select *'仍然調用'ExecuteScalar()',期望返回一個值。嘗試'從...中選擇前1個搜索' –

+0

發佈表格內容。 –

+0

@PaulAbbott我已經嘗試過,但仍然一樣。 –

回答

0

答案感謝PaulAbbott如下命令:

cmd = new SqlCommand(SELECT TOP 1 searches FROM "+label7.Text+" ORDER BY cast(searches as int) DESC