等效于SqlDataSource中的ObjectDataSource.SelectMethod

|| 在ObjectDataSource中,我们有一个称为SelectMethod和TypeName的方法,在其中可以指定一种从中选择数据的方法。 但是SqlDataSource中用于指定要从中选择数据的方法的等效方法是什么?如果没有这样的方法,我该如何指定一种方法来选择数据,例如在ObjectDataSource中
<asp:ObjectDataSource ID=\"ObjEmployees\" runat=\"server\" 
        SelectMethod=\"GetEmployees\" TypeName=\"AllowPaging.GetData\">
</asp:ObjectDataSource>

SqlConnection connection = new SqlConnection(\"server=NIPUNA-PC\\\\SQLEXPRESS; database=KTD; Trusted_Connection=yes;\");
    string commandText = \"SELECT * FROM [Emp]\";
    public DataSet GetEmployees()
    {
        SqlCommand cmd = new SqlCommand(commandText, connection);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        return ds;
    }
    
已邀请:
看到这个:http://www.4guysfromrolla.com/articles/112206-1.aspx SqlDataSource和ObjectDataSource在执行SQL查询或调用对象方法以检索数据之前立即引发其Selecting事件。检索数据后,将触发Selected事件。通过创建Selecting事件处理程序,您可以检查和调整选择数据时使用的参数; 您可以使用这些事件处理程序来指定数据源控件使用哪种方法。     
在SqlDataSource中,它等效于SelectCommand。您可以提供Select查询并将
SelectCommandType
设置为
Text
(默认),也可以使用存储过程并将
SelectCommandType
设置为
StoredProcedure
。     
SQL数据源执行SQL内联,因此没有等效的方法可以在对象上调用方法。您必须使用SeelctCommand直接在UI中提供SQL查询。 如果要使用业务组件执行查询,请坚持使用ObjectDataSource。 HTH。     

要回复问题请先登录注册