New to Telerik UI for WinFormsStart a free 30-day trial

Creating an Object that can be Consumed by ObjectDataSource

Updated over 6 months ago

See the code below for an example object that can be consumed by ObjectDataSource.  Your object needs to be marked with the DataObjectAttribute for the object to be seen by Data Source Configuration Wizard. It also needs a method to select data marked by the DataObjectMethodAttribute (see GetProducts() method in the code sample). 

C#
[DataObjectAttribute]
public class ProductsBO
{
    [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
    public static IEnumerable GetProducts()
    {
        SqlCommand command = new SqlCommand();
        String connectionString = @"Integrated Security=SSPI;Persist Security Info=False; Initial Catalog=Northwind;Data Source=.\sqlexpress";
        command.Connection = new SqlConnection(connectionString);
        command.CommandText = "SELECT CategoryName, SUM(ProductSales) AS TotalSales FROM [Product Sales for 1997] GROUP BY CategoryName";
        command.Connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        return reader;
    }
}
Not finding the help you need?
Contact Support