[英]c# - Paramaters with ObjectDataSource Control
I have a 2-tier architecture, which means I'm working with Business Objects and DAL classes. 我有一个2层架构,这意味着我正在使用Business Objects和DAL类。 My question is: how do you pass a value to the parameters of one of the functions in a DAL class.
我的问题是:如何将值传递给DAL类中某个函数的参数。
I'm working with a gridview (where I display essential information) and a formview (where all of the information of one single record is shown when you click the select button in the gridview). 我正在使用gridview(我显示基本信息)和formview(当你单击gridview中的select按钮时,会显示一条记录的所有信息)。
this is the function in my DAL class: 这是我的DAL类中的函数:
[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
public static Inschrijving GetInschrijvingById(int id)
{
Inschrijving inschrijving = new Inschrijving();
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql =
"SELECT * FROM tblInschrijvingen WHERE ID = @id";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
inschrijving.Id = Convert.ToInt32(dr["ID"]);
inschrijving.Naam = dr["NAAM"].ToString();
inschrijving.Geslacht = dr["GESLACHT"].ToString();
inschrijving.Straat = dr["STRAAT"].ToString();
inschrijving.Postcode = Convert.ToInt32(dr["PC"]);
inschrijving.Gemeente = dr["PLAATS"].ToString();
inschrijving.Geboortedatum = (DateTime) dr["GBDATUM"];
inschrijving.Tshirt = dr["TSHIRT"].ToString();
inschrijving.Afstand = DAL.AfstandDAL.getAfstandByID(Convert.ToInt32(dr["ID_AFSTAND"]));
inschrijving.Email = dr["EMAIL"].ToString();
inschrijving.InschrijvingsDatum = (DateTime)dr["INDATUM"];
inschrijving.Betaald = Convert.ToBoolean(dr["BETAALD"]);
}
return inschrijving;
}
And I have this Object Datasource: 我有这个对象数据源:
<asp:ObjectDataSource ID="dtsrcDetails" runat="server" SelectMethod="getInschrijvingById" OldValuesParameterFormatString="original_{0}" TypeName="DAL.InschrijvingDAL" DataObjectTypeName="BO.Inschrijving"></asp:ObjectDataSource>
I know I'm supposed to add some SelectParameter, I just don't know how. 我知道我应该添加一些SelectParameter,我只是不知道如何。 Anyone that is willing to help me?
有谁愿意帮助我吗? :)
:)
Thanks in advance. 提前致谢。 HS
HS
You can use the ObjectDataSource.SelectParameters property. 您可以使用ObjectDataSource.SelectParameters属性。
This msdn article describes how to use parameters - Using Parameters with the ObjectDataSource Control 这篇msdn文章描述了如何使用参数 - 将参数与ObjectDataSource控件一起使用
You can use the following method to add parameters to be passed to the select method 您可以使用以下方法添加要传递给select方法的参数
<asp:ObjectDataSource ID="dtsrcDetails" runat="server" SelectMethod="getInschrijvingById" OldValuesParameterFormatString="original_{0}" TypeName="DAL.InschrijvingDAL" DataObjectTypeName="BO.Inschrijving"><SelectParameters>
<asp:Parameter Name="id" />
</SelectParameters>
</asp:ObjectDataSource>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.