Binding to an FqlDataSource in Code-Behind

Dec 3, 2007 at 12:51 AM
Does anyone know how to do this? I've brand new to the FacebookNET API (excellent work, Nikhil -- very nice) and still getting familiar with it. If I wanted, say, to bind a ListBox to an FqlDataSource, what do I have to do differently (where fbApp is a handle on a FacebookApplication object)?

FqlDataSource fqlDS = new FqlDataSource();
fqlDS.FqlQuery = "SELECT name, uid from user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = " + fbApp.UserID + ")";

lbFriends.DataSource = fqlDS;
lbFriends.DataTextField = "name";
lbFriends.DataValueField = "uid";
lbFriends.DataBind();

I'm getting a NullRefException on the final line. I'm sure I'm just forgetting something simple -- any help would be appreciated.

Thanks!
Chris
Coordinator
Dec 3, 2007 at 5:06 AM
If you're doing this in code, don't use FqlDataSource. The DataSource isn't a list of records.
Try:

lbFriends.DataSource = fbApp.Service.Fql.Execute(...);
Dec 3, 2007 at 7:01 AM
Ah, excellent -- thanks much.

And thanks again for releasing this. It's great stuff.

Chris


NikhilK wrote:
If you're doing this in code, don't use FqlDataSource. The DataSource isn't a list of records.
Try:

lbFriends.DataSource = fbApp.Service.Fql.Execute(...);


May 29, 2008 at 12:37 AM
Edited May 29, 2008 at 6:49 PM

VB Update:
  

The fbApp.Service.Fql.Execute(...);  is causing errors on the page.  Wouldn't setting up the FqlDataSource and DataKeyName be enough to bind the data as needed on page load?  But, creating a New DataSource is also nice for modifying the FQL Params on the fly.

I have tried the following:     lbfriends.DataSource = fbApp.Service.Fql.ExecuteQuery("myQueryHere")
                                            lbfriends.DataSource = fbApp.Service.Fql.ExecuteQuery(FqlDataSource1.FqlQuery())

What else could be missing, in order for the FqlQuery to execute properly?
(Using VB Script/CodeBehind)

Feedback Appreciated.
May 21, 2010 at 3:38 PM

Hi Cnunciato,

In you last post I see that  you have metioned  "fbApp" is a handle on a FacebookApplication object. Can you please let me know how to create this handle.

Since I need to work on this seriously, appreciate if you can reply me on this.

Please provide a complete example if you can.

I really appreciate if any body else also can espond to this.

Thnaks,

Munni