2012-11-25 73 views
0

我已創建了如何在配置的數據列表中的select查詢中申請循環?

GridLines="Both" RepeatDirection="Horizontal" BorderColor="Black" 
        BorderStyle="None" CellPadding="5" CellSpacing="1" RepeatColumns="6"> 

一個DataList我也創建了數據庫,在那裏他們與ProductID列這是我的表的主鍵 所以這是我插入他們得到插入在數據列表中的項目水平列(增加productid的值)並且其限制超過6個新行被創建。但是我只需要每次只有12個項目,即只有2個行。

我在頁面的頁腳模板中添加了兩個Linkbuttons。我希望當我點擊下一個按鈕時,產品顯示計數從產品id = 13到24等等upto count(n)。

我已經配置我的數據列表與SqlDataSource1和要使用的查詢語句這樣

SelectCommand="SELECT * FROM Products where ProductId>=n and ProductId<=m order by [Sports Name]" 

我宣佈在頁面加載 的M = 1和N = 12,但是當我跑我的網頁下面發生錯誤

Invalid column name 'n'. 
Invalid column name 'm'. 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'n'. 
Invalid column name 'm'. 

現在請幫我在我的項目中做這種類型的編碼。

回答

0

嘗試的String.format

SelectCommand = string.Format("SELECT * FROM Products where ProductId={0} and ProductId={1} order by [Sports Name]", n, m); 
+0

這個說法ISS生成語法錯誤分析器錯誤 說明:該請求提供服務所需資源的分析過程中發生錯誤。請檢查以下特定的分析錯誤詳細信息並適當修改您的源文件。 –

+0

SelectCommand設置在.ASPX文件中,因此不能像使用String.Format()那樣使用VB代碼。 –