博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

SqlDataSource---参数(高级)

Posted on 2010-09-12 11:22  EVON168  阅读(1662)  评论(0编辑  收藏  举报

重点掌握:

ControlParameter

将参数设置为ASP.net网页中的的Control的属性值。使用controlID属性指定control.

使用Controlparameter对象PropertyName属性指定提供参数值 的属性的名称。

从control派生的某些控件将定义ControlValuePropertyAttribute,从而确定从中检索控件的默认属性。

只要没有显式设置设置propertyName属性,就会使用默认属性。

--通过设置SqlDataSource的InsertQuary

<InsertParameters>
                
<asp:ControlParameter ControlID="txtuserid" Name="StuID" PropertyName="Text" 
                    Type
="String" />
                
<asp:ControlParameter ControlID="txtusername" Name="StuName" 
                    PropertyName
="Text" Type="String" />
                
<asp:ControlParameter ControlID="txtclass" Name="ClassID" PropertyName="Text" 
                    Type
="String" />
                
<asp:ControlParameter ControlID="txtuserage" Name="StuAge" PropertyName="Text" 
                    Type
="Int32" />
            
</InsertParameters>

 

 

QueryStringParameter

将参数设置为QueryString字段的值,使用QueryStringField属性指定QueryString字段的名称。如果指定的QueryString字段不存在,则将使用DefaultValue属性的值作为参数。

代码体现:

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString
="<%$ ConnectionStrings:NorthwindconnectionString %>" 
            SelectCommand
="SELECT [StuID], [StuName], [ClassID], [StuAge] FROM [Student] WHERE ([ClassID] = @ClassID)">
            
<SelectParameters>
                
<asp:QueryStringParameter Name="ClassID" QueryStringField="cid" Type="String" />
            
</SelectParameters>
        
</asp:SqlDataSource>

 

视图操作(在添加sqldatasource时选择WHERE子句)