Question

Is there any way how to get a SQL query result from a bltoolkit? I need to set the query explicitly..

for example:

SELECT * FROM table

thanks

Was it helpful?

Solution

Yes. The DbManager class contains some appropriate methods: ExecuteList, ExecuteReader, ExecuteObject, ExecuteDataTable, SetSpCommand, etc. See there: http://bltoolkit.net/Doc.Data.ashx

Sample:

[MapField("PersonID", "ID")]
public class Person
{
    public int    ID;

    public string LastName;
    public string FirstName;
    public string MiddleName;
    public Gender Gender;
}

IList<Person> GetPersonListSqlText()
{
    using (DbManager db = new DbManager())
    {
        return db
            .SetCommand("SELECT * FROM Person")
            .ExecuteList<Person>();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top