2011-10-17 43 views
0

我對asp.net很新,我正在構建一個應用程序,我需要在網格視圖中顯示,現在我正在生成的查詢來獲取數據含有來自查詢string.I一個參數數據庫正在使用此代碼訪問查詢字符串變量在aspx頁面的sql查詢

<asp:SqlDataSource runat="server" ID="MySQLData" 
    ConnectionString="server=localhost;port=3309; User Id=xxxxx;password=xxxxx;database=xxxxx" 
    ProviderName="MySql.Data.MySqlClient" 
    SelectCommand="SELECT contenthead.lastmodifieddate,contenthead.heading,lk_technology.technology FROM contenthead JOIN lk_technology WHERE contenthead.techID=lk_technology.techID AND contenthead.authorid='<%=Request.QueryString["uid"]%>'" /> 

現在,當我使用<%..%>標籤我得到解析錯誤,說:服務器標記不能包含<% ...%>構造。

現在我想從查詢字符串中使用這個變量。請告訴我如何在此上下文中訪問此變量。

回答

1
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="..." ProviderName="System.Data.SqlClient" SelectCommand="SELECT [UserId], [LastUpdatedDate] FROM [vw_aspnet_Profiles] WHERE ([UserId] = @UserId)"> 
<SelectParameters> 
<asp:QueryString ParameterDefaultValue="0" Name="UserId" QueryStringField="Id" Type="Object"/> 
</SelectParameters> 
</asp:SqlDataSource> 

你有一個參數添加到您的SqlDataSource

+0

謝謝您reply..but我收到此錯誤,請參閱此URL:http://bugnull.hinduyuvamanch.com/edit_home .aspx?uid = 1(這是我的測試服務器) –

+1

請給asp:QueryStringParameter和DefaultValue之間的空白以及asp的其他屬性:QueryStringParameter – rahularyansharma

+0

感謝您的答覆,這工作.. –