gpt4 book ai didi

c# - 如何在 SqlDataSource select Command where 条件中传递属性值?

转载 作者:太空狗 更新时间:2023-10-30 01:08:09 25 4
gpt4 key购买 nike

我的 page2.aspx.cs 页面中有一个属性

public int? Id
{
get
{
if (ViewState[Page1.Id] != null)
return Convert.ToInt32(ViewState[Page1.Id]);
else return null;
}
set
{
ViewState[Id] = value;
}
}

我正在使用 asp: 数据源:

<asp:SqlDataSource ID="SqlDataSourceGridView" runat="server" 
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [Name],[Address] FROM [Table_Emp] where Id = need to pass property value >"
OnSelecting="SqlDataSourceGridView_Selecting">
</asp:SqlDataSource>

我想在我的 where 条件中传递 Id。怎么可能。

请有人帮助我。

最佳答案

看这里

 <asp:sqlDataSource ID="EmployeeDetailsSqlDataSource" 
SelectCommand="SELECT EmployeeID, LastName, FirstName FROM Employees WHERE EmployeeID = @EmpID"

InsertCommand="INSERT INTO Employees(LastName, FirstName) VALUES (@LastName, @FirstName);
SELECT @EmpID = SCOPE_IDENTITY()"
UpdateCommand="UPDATE Employees SET LastName=@LastName, FirstName=@FirstName
WHERE EmployeeID=@EmployeeID"
DeleteCommand="DELETE Employees WHERE EmployeeID=@EmployeeID"

ConnectionString="<%$ ConnectionStrings:NorthwindConnection %>"
OnInserted="EmployeeDetailsSqlDataSource_OnInserted"
RunAt="server">

<SelectParameters>
<asp:Parameter Name="EmpID" Type="Int32" DefaultValue="0" />
</SelectParameters>

<InsertParameters>
<asp:Parameter Name="EmpID" Direction="Output" Type="Int32" DefaultValue="0" />
</InsertParameters>

</asp:sqlDataSource>

关于c# - 如何在 SqlDataSource select Command where 条件中传递属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10347423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com