如何使用Entity Framework存储过程填充win表单图表数据源? [英] How to populate a win forms chart datasource with a Entity Framework stored procedure?

查看:98
本文介绍了如何使用Entity Framework存储过程填充win表单图表数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VB.NET / Visual Studio 2015.实体框架6. Windows窗体应用程序。 SQL Server 2014

I am using VB.NET/ Visual Studio 2015. Entity Framework 6. Windows Forms Application. SQL Server 2014

如何使用Entity Framework存储过程填充win表单图表数据源?

How do I populate a win forms chart datasource with a Entity Framework stored procedure?

推荐答案

嗨kingelk,

Hi kingelk,

根据您的描述,我创建了一个简单的演示供您参考。

Based on your description, I create a simple demo for your reference.

#Table。

CREATE TABLE [dbo].[Account] (
    [account_id] INT          NOT NULL,
    [Name]       VARCHAR (50) NULL,
    [Count]      INT          NULL
);

#Stored Procedure

#Stored Procedure

CREATE PROCEDURE [dbo].[GetAccountInfo]
	
AS
	SELECT * from [dbo].[Account]
RETURN 0

#Usage(优先代码优先)

#Usage(Ef code first)

using System;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApp
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (var db = new AdoNetContext())
            {
                var query = db.Accounts.SqlQuery("GetAccountInfo").ToList();

                string[] N = new string[query.Count()];
                int[] M = new int[query.Count()];

                int i = 0;

                foreach (var item in query)
                {
                    N[i] = item.Name;
                    M[i] = (int)item.Count;
                    i++;
                }
                chart1.Series[0].Points.DataBindXY(N, M);
            }
        }
    }
}

祝你好运,

Cole Wu


这篇关于如何使用Entity Framework存储过程填充win表单图表数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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