如何在应用程序的datagrid视图中显示SQL视图 [英] How to display SQL view in datagrid view in a application

查看:93
本文介绍了如何在应用程序的datagrid视图中显示SQL视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示我在应用程序前端的数据网格中创建的sql View,但是我一直收到一个错误,即该对象是一个无效的名称。



前端显示数据的方法:

I need to display a sql View I created in a datagrid in the front end of the application, but I keep getting a error that the object is a invalid name.

Method in front end to display the data:

private void EmpMostSales()
        {

            string sqlcmd = "select * from [Doodle_Customers].[dbo].[Empwithmostsales]";
            SqlDataAdapter da1 = new SqlDataAdapter(sqlcmd, con);
            DataTable dt1 = new DataTable();
            da1.Fill(dt1);
            datag.ItemsSource = dt1.DefaultView;

        }







SQL视图




SQL view

Create view Empwithmostsales
AS
SELECT TOP(3)
      COUNT (Orders.Emp_ID) AS Top_Sale_Employee,
	   Employees.First_Name
FROM   [Doodle_Customers].[dbo].[Orders] 
INNER JOIN
[Doodle_Customers].[dbo].[Employees] ON Orders.Emp_ID = Employees.ID
GROUP BY Employees.First_Name
ORDER BY COUNT (Orders.Emp_ID) DESC
go

select * from Empwithmostsales
go





我是什么尝试过:



尝试使用select语句中的模式



What I have tried:

Tried using the schema in the select statement

推荐答案

你是必然需要使用数据库名称。如果您当前的数据库是正确的,以下内容就足够了

Do you necessarily need to use the database name. If your current database is correct, the following should suffice
string sqlcmd = "select * from Empwithmostsales";



但是,请记住,用于连接的用户帐户需要具有该视图的权限。


However, keep in mind that the user account you use for the connection needs to have privileges to the view.


这篇关于如何在应用程序的datagrid视图中显示SQL视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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