Reputation: 569
I have a 2-tier architecture, which means I'm working with Business Objects and DAL classes. My question is: how do you pass a value to the parameters of one of the functions in a DAL class.
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).
this is the function in my DAL class:
[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. Anyone that is willing to help me? :)
Thanks in advance. H.S.
Upvotes: 0
Views: 1580
Reputation: 7854
You can use the following method to add parameters to be passed to the select method
<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>
Upvotes: 1
Reputation: 22587
You can use the ObjectDataSource.SelectParameters property.
This msdn article describes how to use parameters - Using Parameters with the ObjectDataSource Control
Upvotes: 1