[英]c# - Paramaters with ObjectDataSource Control
我有一個2層架構,這意味着我正在使用Business Objects和DAL類。 我的問題是:如何將值傳遞給DAL類中某個函數的參數。
我正在使用gridview(我顯示基本信息)和formview(當你單擊gridview中的select按鈕時,會顯示一條記錄的所有信息)。
這是我的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;
}
我有這個對象數據源:
<asp:ObjectDataSource ID="dtsrcDetails" runat="server" SelectMethod="getInschrijvingById" OldValuesParameterFormatString="original_{0}" TypeName="DAL.InschrijvingDAL" DataObjectTypeName="BO.Inschrijving"></asp:ObjectDataSource>
我知道我應該添加一些SelectParameter,我只是不知道如何。 有誰願意幫助我嗎? :)
提前致謝。 HS
您可以使用ObjectDataSource.SelectParameters屬性。
這篇msdn文章描述了如何使用參數 - 將參數與ObjectDataSource控件一起使用
您可以使用以下方法添加要傳遞給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.