从存储过程填充的DataGridView [英] Populate DataGridView from a Stored Procedure

查看:114
本文介绍了从存储过程填充的DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用SQL Server 2008中我创建了一个存储过程称为MyStoreProc和运行良好的管理工具。

Using SQL Server 2008 I created a Stored Procedure called MyStoreProc and it runs fine from the Management Tools.

在2008年VB.Net我创建了一个新的数据集和新的TableAdaptor。在这个表适配器我创建了一个新的查询称为FillByGrid和选择的存储过程。 previewed数据,并将其正确previewed。

In VB.Net 2008 I created a new dataset and a new TableAdaptor. In this table adapter I created a new Query called FillByGrid and selected the Stored Procedure. Previewed data and it previewed correctly.

在一个表格,我创建的DataGridView,并从数据集中选择的表适配器。

On a form I created DataGridView and selected the Table Adapter from the dataset.

我跑的应用程序,并没有数据显示。 Visual Studio中自动创建低于code,我把它改为选择查询我刚刚创建的:

I ran the app and no data is shown. Visual Studio autocreated the code below and I changed it to select the the Query I just created:

Me.MyTableAdapter.FillByGrid(Me.MyDataset.MyTableAdaptor)

没有数据显示在网格所以我尝试手动方法:

No data is shown on the grid so I tried the manual approach:

' Create the dataset
Dim da As New SqlDataAdapter, ds As New DataSet
Dim conn As New SqlConnection

conn.ConnectionString = opsData.DBConn.ConnectionString
da.SelectCommand = New SqlCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandType = CommandType.StoredProcedure
da.SelectCommand.CommandText = "dbo.MyStoreProc"
da.Fill(ds, "tbl1")
DataGridView2.DataSource = ds.Tables("tbl1")

仍然显示没有数据。但是通过加强我可以看到连接是开放的,da.Fill(DS,TBL 1)所花的时间一点点,因为它运行的是存储过程和DS表有行和列的正确数量。它只是没有被显示在DataGrid中。

Still no data shown. However stepping through the I can see that the connection is open, and "da.Fill(ds, "tbl1")" takes a little bit of time as it is running the Stored Procedure and ds table has the correct number of rows and columns. Its just not being shown on the datagrid.

在数据集中创建另一个表适配器使用标准SELECT * from表命令显示在DataGridView罚款从数据库表中返回数据。

Creating another table adapter in the dataset and returning data from a database table using a standard select * from table command display in the datagridview fine.

有没有人有什么建议?

感谢您

推荐答案

似乎有丰富提供了有关如何做到这一点的资源。最好的来源是: http://www.asp.net/learn/data-access/ -

There seem to be a wealth of resources available on how to do this. The best source would be: http://www.asp.net/learn/data-access/ -

如果做不到这一点一个良好的老式<一href="http://www.liquidjelly.co.uk/supersearch/?q=Populate%20DataGridView%20from%20a%20Stored%20Procedure&lang=en-GB"相对=nofollow>搜索会产生大量的太。

Failing that a good old fashioned search yields lots too.

这篇关于从存储过程填充的DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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