使用C#(WinForms)显示FQL结果DataGridView [英] Display FQL results in DataGridView using C# (WinForms)

查看:110
本文介绍了使用C#(WinForms)显示FQL结果DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的FQL查询,我有我的访问令牌。但是如何使用C#和ASP.NET在GRID VIEW中显示FQL结果?



FQL:

  SELECT uid,username,first_name,last_name,friend_count,pic_big 
FROM user
WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me ))

这是我试过的:

 使用系统; 
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用Facebook;

命名空间WindowsFormsApplication1
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent() ;
}

private void Form1_Load(object sender,EventArgs e)
{
var fb = new FacebookClient({My Access Token});

动态结果= fb.Get(/ me);
var name = result.name;

MessageBox.Show(嗨+名称);
}
}
}

我已经意识到数据作为JSON从Facebook返回,所以我试图 deserialize ,但现在仍然运气。

 使用系统; 
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用Facebook;
使用System.Dynamic;
使用Newtonsoft.Json;

命名空间WindowsFormsApplication1
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent() ;
}

private void Form1_Load(object sender,EventArgs e)
{

}


public MyFriends类
{
public int uid {get; set;}
public string username {get; set;}
public string first_name {get; set;}
public string last_name {get; set;}
public int friend_count {get; set;}
public string pic_big {get; set;}
}


private void button1_Click(object sender,EventArgs e)
{
var fb = new FacebookClient(2A64ZAIeJVIbdZAxXRZCwYf5Bg27OgZDZD);

var query = string.Format(SELECT uid,username,first_name,last_name,friend_count,pic_big FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()));

动态参数= new ExpandoObject();
parameters.q = query;
动态结果= fb.Get(/ fql,参数);

results = JsonConvert.DeserializeObject&MyFriends>(results);

//MessageBox.Show(\"Hi+ results);
}
}
}


解决方案

C# Winforms 解决方案使用您在标题中指定的 DataGridView 控件。






1)修改您的 MyFriend class ,我更改了一点点

  public class MyFriends 
{
public long uid {get;组; }
public string username {get;组; }
public string first_name {get;组; }
public string last_name {get;组; }
public long? friend_count {get;组; } // nullable
public string pic_big {get;组;
}

2)将DataGridView控件添加到表单



3)反序列化 result.data 使用 JsonConvert 到列表你也应该通过 result.data.ToString()或者它会给出例外。



4)绑定您的新列表 DataGridView.Datasource

  var fb = new FacebookClient(accessToken); 

var query = string.Format(@SELECT uid,username,first_name,last_name,friend_count,pic_big
FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()) );

动态参数= new ExpandoObject();
parameters.q = query;
动态结果= fb.Get(/ fql,参数);

列表< MyFriends> q = JsonConvert.DeserializeObject< MyFriends>>(results.data.ToString());

dataGridView1.DataSource = q;

结果:


I have my FQL query and i have my access token. But how do i display FQL results in GRID VIEW using C# and ASP.NET?

FQL:

SELECT uid, username, first_name, last_name, friend_count, pic_big  
FROM user 
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) 

This is what i have tried:

 using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Facebook;

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                var fb = new FacebookClient("{My Access Token}");

                dynamic result = fb.Get("/me");
                var name = result.name;

               MessageBox.Show("Hi " + name);
            }
        }
    }

I have realized that the data is returned from Facebook as JSON so i attempt to deserialize but still now luck.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Facebook;
using System.Dynamic;
using Newtonsoft.Json;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }


        public class MyFriends
        {
            public int uid {get; set;}
            public string username {get; set;}
            public string first_name {get; set;}
            public string last_name {get; set;}
            public int friend_count {get; set;}
            public string pic_big {get; set;}
        }


        private void button1_Click(object sender, EventArgs e)
        {
            var fb = new FacebookClient("2A64ZAIeJVIbdZAxXRZCwYf5Bg27OgZDZD");

            var query = string.Format("SELECT uid, username, first_name, last_name, friend_count, pic_big  FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())");

            dynamic parameters = new ExpandoObject();
            parameters.q = query;
            dynamic results = fb.Get("/fql", parameters);

            results = JsonConvert.DeserializeObject<MyFriends>(results);

            //MessageBox.Show("Hi " + results);
        }
    }
}

解决方案

C# Winforms solution using a DataGridView control like you specify in the title.


1) Modify your MyFriend class, I changed it a little bit

public class MyFriends
{
    public long uid { get; set; }            
    public string username { get; set; }
    public string first_name { get; set; }
    public string last_name { get; set; }
    public long? friend_count { get; set; }  //nullable
    public string pic_big { get; set; }
}

2) Add DataGridView control to your form

3) Deserialize your result.data using JsonConvert to a List. You should also pass result.data.ToString() or it will give an exception.

4) Bind your new list to DataGridView.Datasource

var fb = new FacebookClient("accessToken");

var query = string.Format(@"SELECT uid, username, first_name, last_name, friend_count, pic_big 
                            FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())");

dynamic parameters = new ExpandoObject();
parameters.q = query;
dynamic results = fb.Get("/fql", parameters);

List<MyFriends> q = JsonConvert.DeserializeObject<List<MyFriends>>(results.data.ToString());

dataGridView1.DataSource = q;

Result:

这篇关于使用C#(WinForms)显示FQL结果DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆