borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (Accessing Access 2000 with VB6) New Topic New Poll Post Reply
AndreaVB Forum : Database : Channging datasource on ADO
Poster Message
Ozzy1234
Level: Trainee

Registered: 29-02-2008
Posts: 3

icon Channging datasource on ADO

I have an application where a Datagrid is bound to an ADO datacontrol.
I have typed in the relevant SQL into the RecordSource of the ADO control and the Datagrid fills up as required.

However, at runtime, I need to change the SQL statement depending on circumstances.
When I do this, the grid contents don't change at all.
Can I dynamically alter the Recordsource porperty?

The code is below ..
The grid is called grdmembership.
The datacontrol is called AdoMembership

grdMembership.ClearFields
AdoMembership.RecordSource = "SELECT Board_ID, Membership_ID FROM tblMembership WHERE Board_ID LIKE '" & Trim(Working.BoardID) & "%'"
grdMembership.ReBind
grdMembership.Refresh

29-02-2008 at 03:05 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 1030
icon Re: Channging datasource on ADO

Hi,
The answer is "Yes" you can alter the source SQL.
What problems have you found?


[Edited by stickleprojects on 05-03-2008 at 03:28 PM GMT]

____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

05-03-2008 at 03:27 PM
View Profile Send Email to User Show All Posts | Quote Reply
Ozzy1234
Level: Trainee

Registered: 29-02-2008
Posts: 3
icon Re: Channging datasource on ADO

Hi, Thanks for your reply.  
The problem is that, when I change the Recordsource, I can't get the grid to reflect the changes.
It still has the data in which was retrieved from the Recordource held by the data control when the form loaded.

It looks like I need to explicitly tell it to refresh its data, but I have tried various combinations of Refresh and Rebind without any joy!

05-03-2008 at 05:08 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 1030
icon Re: Channging datasource on ADO

HI
Ensure you are using the latest SP (There's some dodgy stuff about the datagrid in the later sps for visual studio)
grdMembership.datasource = adoMembership should do it


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

16-05-2008 at 05:17 AM
View Profile Send Email to User Show All Posts | Quote Reply
Ozzy1234
Level: Trainee

Registered: 29-02-2008
Posts: 3
icon Re: Channging datasource on ADO

I think I have cracked it now.
I hadn't set the 'DataChanged' property of the grid to True - hence it never went looking for the new data.
Did this and it all sprang to life.

Thanks for everyones replies.

16-05-2008 at 02:43 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : Channging datasource on ADO
Next Topic (Accessing Access 2000 with VB6) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Il portale per lui e lei | Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder