命令objectdatasource和sqldatasource中的参数值 [英] Commands Parameter values in objectdatasource and sqldatasource
本文介绍了命令objectdatasource和sqldatasource中的参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在ObjectDataSource和SqlDataSource中,命令参数在何处接收到它们的值?
in ObjectDataSource and SqlDataSource ,Commands Parameters where received their values ?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>: DataSet in Web :</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button runat="server" ID="Submit" Text="Do Post Back" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ShopConnectionString2 %>"
DeleteCommand="DELETE FROM [Customer] WHERE [ID] = @ID" InsertCommand="INSERT INTO [Customer] ([Code], [FirstName], [LastName], [TimeStamp]) VALUES (@Code, @FirstName, @LastName, @TimeStamp)"
SelectCommand="SELECT * FROM [Customer]" UpdateCommand="UPDATE [Customer] SET [Code] = @Code, [FirstName] = @FirstName, [LastName] = @LastName WHERE [ID] = @ID">
Product<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource1" Font-Bold="False" Font-Size="11pt">
<columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
</columns>
</div>
</form>
</body>
</html>
推荐答案
ConnectionStrings:ShopConnectionString2%> DeleteCommand =从[客户]那里删除[ID] = @ID" InsertCommand ="INSERT INTO [客户]([代码],[名字],[姓],[时间戳])值(@Code,@名字,@姓氏,@ TimeStamp)" SelectCommand ="SELECT * FROM [Customer]" UpdateCommand ="UPDATE [Customer] SET [Code] = @Code,[FirstName] = @FirstName,[LastName] = @LastName,其中[ID] = @ID"> 产品< asp:GridView ID ="GridView1" runat =服务器" AutoGenerateColumns ="False" DataKeyNames ="ID" DataSourceID ="SqlDataSource1" Font-Bold ="False" Font-Size ="11pt"> <列> < asp:CommandField ShowEditButton ="True"/> < asp:BoundField DataField ="ID" HeaderText ="ID" InsertVisible ="False" ReadOnly ="True" SortExpression ="ID"/> < asp:BoundField DataField ="Code" HeaderText ="Code" SortExpression ="Code"/> < asp:BoundField DataField ="FirstName" HeaderText ="FirstName" SortExpression ="FirstName"/> < asp:BoundField DataField ="LastName" HeaderText ="LastName" SortExpression ="LastName"/> </列> </div> </form> </body> </html>
ConnectionStrings:ShopConnectionString2 %>" DeleteCommand="DELETE FROM [Customer] WHERE [ID] = @ID" InsertCommand="INSERT INTO [Customer] ([Code], [FirstName], [LastName], [TimeStamp]) VALUES (@Code, @FirstName, @LastName, @TimeStamp)" SelectCommand="SELECT * FROM [Customer]" UpdateCommand="UPDATE [Customer] SET [Code] = @Code, [FirstName] = @FirstName, [LastName] = @LastName WHERE [ID] = @ID"> Product<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" Font-Bold="False" Font-Size="11pt"> <columns> <asp:CommandField ShowEditButton="True" /> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /> <asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" /> <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" /> <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" /> </columns> </div> </form> </body> </html>
如果您查看GridView声明,将会看到以下属性:
If you look at the GridView declaration you''ll see this attribute:
DataSourceID="SqlDataSource1"
这将连接GridView和数据源.然后,数据源隐式将DataField属性映射到参数:
This connects the GridView and the DataSource. The DataSource then implicitly maps the DataField attribute to the parameters:
<asp:BoundField DataField="Code"
这篇关于命令objectdatasource和sqldatasource中的参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文