Link to home
Start Free TrialLog in
Avatar of Member_2_4286571
Member_2_4286571

asked on

Fill tableAdapter with selected data only

Hello experts,

I would like to fill datagrid with data filtered by date. I can fill all the data into tableadapter and then use filter, but i would like to avoid that since after a while there is lot's of data and everything start to slow down.

currently i am using Me.TableAdapter.Fill(Me.db_data.Dates), is there simple way to pull only selected data from database and ignoring the rest.

For example  Me.TableAdapter.Fill(Me.db_data.Dates, "20110302") or something like that.

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of EYoung
EYoung
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_4286571
Member_2_4286571

ASKER

I am accessing both, local and served depends on situation however with local i have no problem, but when acessing database over internet connection slowdowns are noticable.

I am playing with few different solutions, will post here solution that worked for me.

I have found on MSDN forums something that may help with this, but since i am still new to vb.net i will need some help from you guys.

This code below should go into dataset code.

-----------------------------------------------
Namespace myDataSetTableAdapters
    Partial Class myTableAdapter

        Public ReadOnly Property selectcommand() As System.Data.SqlClient.SqlCommand
            Get
                Return Me.CommandCollection(0)
            End Get

        End Property

    End Class
End Namespace
--------------------------------------------------

In your code, you can now set the select command via the following line:

Me.myTableAdapter.selectcommand.CommandText = "select * from table"

I tried this but i am getting "CommandCollection is not a member of mydatasettableadapters..." error at this part of the code "Return Me.CommandCollection(0)"

Forum thread where i found this is:MSDN Forums

Am I on the right track with this one?

Ok i solved this in different way.

In TableAdapter i added new query  "SELECT Date,Brrac... FROM dbo.data where Date=@Date" and saved as FillByDate.

then in my code i call Me.TableAdapter.Fill(Me.db_data.Dates, dtpDate.value.date)

dtpDate is datetimepicker.

This works perfectly, but now how would i construct this to load selection between two different dates.

Lets say I have dtpDate1 and dtpDate2. Now I want to construct query so it will show only dates that are equal to dtpDate1 and dtpDate2, and dates between.

Thanks for all assistance so far.



edit:

small typo in: "Me.TableAdapter.FillByDate(Me.db_data.Dates, dtpDate.value.date)"