How we can use SQL query in DataSet Or DataTable

How we can use SQL query in DataSet Or DataTable

I means to say can we use group by clause and other clause that we generally used with database table.



Answer this question

How we can use SQL query in DataSet Or DataTable

  • Kajal Sinha

    You can use Select Method of DataTable Class (input the Filter Expression) .

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpref/html/frlrfsystemdatadatatableclassselecttopic.asp

    Thanks.


  • rblaco

    Hi, Sunil

    You can use any valid select query to populate dataset or datatable, check this code

    Dim cn As New Odbc.OdbcConnection(ClsMain.ConneStr)

    cn.Open()

    Dim da As Odbc.OdbcDataAdapter

    Dim ds As New Data.DataSet

    Dim stmt As String

    stmt = "select Department, count(*) from Emp_Master group by Department"

    da = New Odbc.OdbcDataAdapter(stmt, cn)

    da.Fill(ds, "EmpDept")

    In this code i connect to mysql database databse with odbc connection, you can change the connection string as per your data sourec, and change the Sql query to populate the dataset.

    Happy coding



  • bagira20572

    www.queryadataset.com is what you are looking for.

    Ad.


  • Syed Junaid

    hi,

    i don't know anyway to do the same thing as group by in SQL to a single table , but you can use relations to group by a parent table http://msdn.microsoft.com/library/default.asp url=/library/en-us/dndive/html/data05312002.asp

    table columns has expression property you can use it to search for solution , if you reach to any solution for this plz let me know

    best regards



  • xpach

    to select a set of rows you can use a dataview

    DataView dv = new DataView(MyDataset.Tables["TableName"], "Column1 = " + TestNumtextBox.Text + "and Column2 Like '%" + VehNumtextBox.Text+ "%'","", DataViewRowState.CurrentRows);

    you can iterate through the rows in dataview like this

    foreach (DataRowView drv in dv)

    {

    value = (int)drv["column1"];

    }

    or you can use an array of rows like

    DataRow[] rows = table.select ("the same filter string as Dataview")method the string in the filter property will be the same as SQL Where clause

    but the other operation like group by ... etc in SQL Select Clause you will find it in expression as the link i posted b4

    hope this helps



  • *ferhat

    Atanu Sir

    I don't want to populate the dataset from SQL query.

    I had already fill whole data in dataset. Now I want the particuler records from dataset by executing query in dataset. So please guide me to how I can do the same.

    Sunil Sinha


  • lukeliu

    Atanu Sir

    I don't want to populate the dataset from SQL query.

    I had already fill whole data in dataset. Now I want the particuler records from dataset by executing query in dataset. So please guide me to how I can do the same.

    Sunil Sinha


  • How we can use SQL query in DataSet Or DataTable