使用VB.NET和SQL Server将2个或更多表加载到单个DataSet中 [英] Loading 2 or more Tables Into a single DataSet using VB.NET and SQL server

查看:188
本文介绍了使用VB.NET和SQL Server将2个或更多表加载到单个DataSet中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您的帮助,但是现在对于应用程序,我需要将两个以上的表加载到单个DataSet中,但请记住,我还不熟悉SQL Server 2008中的存储过程,我正在使用的代码如下:如下图所示.请盖茨帮我,我还是VB.NET的新手.

Thanx guys for the help But now for application I need load more than 2 tables into a single DataSet but please do bare in mind that I am NOT YET Familiar with stored procedures in SQL Server 2008 the code that I am using is as shown below.Please guyz do help me I am still new to VB.NET

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
    Public Sub New()
        InitializeComponent()
        '' connect to my local server, northwind db
        Dim connectionString As String = _
            "server=localhost; " & _
            "Integrated Security=True; " & _
            "database=Northwind"

        Dim commandString As String = _
        "Select CompanyName, ContactName, ContactTitle, " & _
        "Phone, Fax from Customers"

        '' create a data set and fill it
        Dim myDataAdapter As _
        New SqlDataAdapter(commandString, connectionString)
        Dim myDataSet As New DataSet()
        myDataAdapter.Fill(myDataSet, "Customers")

        '' bind the DataSet to the grid
        CustomerDataGrid.DataSource = _
            myDataSet.Tables("Customers").DefaultView
    End Sub ''New

推荐答案

通过用;
分隔来编写另一个查询
Write another query by separating with ;
Dim commandString As String = _
        "Select CompanyName, ContactName, ContactTitle, " & _
        "Phone, Fax from Customers; " & _
        " Select * from tablename"


尝试使用存储过程 [ http://www.sql-server-performance.com/2003/stored-procedures-basics / [^ ]


Try to use Stored Procedure[^] always.
Check this link for more info.

http://www.sql-server-performance.com/2003/stored-procedures-basics/[^]


仅因为您在VB中进行编码并不意味着您无需熟悉SQL.毕竟,您的命令字符串是SQL.无论您是否正在编写存储的proc,您仍然必须知道如何编写查询.我个人认为使用SQLServer Manager Express编写查询更容易,因为您可以测试它而不必不断停止编辑代码和编译应用程序.

最后,我怀疑您想执行多个查询并将返回的表放入数据集中.我通过简单的Google搜索数据集中的c#个表"发现了这一点:

数据集中的多个表 [
Just because you''re coding it in VB doesn''t mean you''re free from having to be familiar with SQL. Afterall, your command string is SQL. Regardless of whether or not you''re writing a stored proc, you still have to know how to write your query. I personally think it''s easier to use SQLServer Manager Express to write a query because you can test it without having to continually stop to edit code and compile your app.

In the end, I suspect you want to perform multiple queries and have the returned tables put into your dataset. I found this with a simple google search for "c# multiple tables in dataset":

Multiple Tables in Dataset[^]


这篇关于使用VB.NET和SQL Server将2个或更多表加载到单个DataSet中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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