Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 具有多个表的数据集_.net_Ado.net - Fatal编程技术网

.net 具有多个表的数据集

.net 具有多个表的数据集,.net,ado.net,.net,Ado.net,我有个小问题。我不知道如何正确使用VB.NET中的数据集 在VisualStudio2008中,我创建了一个名为Network的数据集。对于数据集,我从数据库中获取了两个表:tServer和tClient。tClient有一个外键引用tServer中的ID 创建数据集后,我发现了一个名为NetworkTableAdapter的新名称空间,其中包含用于tServer、tClient和AdapterManager的适配器。还有一个名为Network的新类,它是DataSet,包含tServer和tC

我有个小问题。我不知道如何正确使用VB.NET中的数据集

在VisualStudio2008中,我创建了一个名为Network的数据集。对于数据集,我从数据库中获取了两个表:tServer和tClient。tClient有一个外键引用tServer中的ID

创建数据集后,我发现了一个名为NetworkTableAdapter的新名称空间,其中包含用于tServer、tClient和AdapterManager的适配器。还有一个名为Network的新类,它是DataSet,包含tServer和tClient的DataTables

但是我如何用数据填充这些数据集并访问它呢?适配器只有GetData和Fill方法,它们填充DataTable,但我想填充DataSet

对不起,我的英语不好,我希望有人能理解我的问题并能帮助我


Torben

据我所知,您无法用这种方式自动填充完整的数据集。您必须填充其中的每个表。为此,如果您正在使用可视化数据集,只需右键单击表适配器,然后添加查询。从这里,您可以直接将SQL添加到表适配器中,或者使用存储过程

对于select示例,select必须与数据集中的列匹配

因此,如果我们有一个名为CustomersTable的数据表,并且我们添加了一个名为GetNewCustomers的func,那么可以执行CustomersTable dtCustomers=adapter.GetNewCustomers

请参阅更好的说明和教程,从1和2开始

然而,数据集是.NET2.0。我建议您先了解它们,然后查看LINQ2实体以映射数据库


希望这有帮助。

我们从返回多个结果集表的存储过程中填充数据集。 我们俄克拉何马州机构的巫师们做了这件事,我只是制作样板表格

SP返回3个结果集:

CREATE PROCEDURE dbo.GetAllLists
AS

SELECT UserKey, FirstName, MiddleInitial, LastName, Suffix, EmailAddress, PeopleSoftID, ChangeDate, ChangeUser
FROM USERS
ORDER BY LastName, FirstName

SELECT a.UserKey, a.DisciplineID, b.Description AS 'DisciplineDescription'
FROM USER_DISCIPLINES a
INNER JOIN Discipline b ON a.DisciplineID = b.DisciplineID

SELECT a.UserKey, a.ApplicationID, b.ApplicationName, a.UserName, a.UserSID, a.UserDomain, a.Active, a.Integrated, a.PositionID, a.ChangeUser, a.ChangeDate
FROM USER_MAPPINGS a
INNER JOIN APPLICATION_TABLE b ON a.ApplicationID = b.ApplicationID
CLSDatam管理程序-完成工作的部分程序

Public Shared Function GetInfoInDataset(ByVal StoredProcedureName As String, ByVal DatabaseID As Integer, ByVal ParamArray SQLParams() As SqlClient.SqlParameter) As DataSet
    Dim dsTemp As New DataSet
    Dim cmdSQL As SqlClient.SqlCommand = Nothing
    Dim conSQL As SqlClient.SqlConnection = Nothing
    Dim daSQL As SqlClient.SqlDataAdapter = Nothing
    Try
        conSQL = New SqlClient.SqlConnection(BuildConnection(DatabaseID))
        conSQL.Open()
        cmdSQL = New SqlClient.SqlCommand(StoredProcedureName, conSQL)
        cmdSQL.CommandType = CommandType.StoredProcedure
        cmdSQL.CommandTimeout = 60
        If Not IsNothing(SQLParams) Then
            For Each p As SqlClient.SqlParameter In SQLParams
                If Not IsNothing(p) Then
                    If IsNothing(p.Value) Then p.Value = DBNull.Value
                    cmdSQL.Parameters.Add(p)
                End If
            Next
        End If
        daSQL = New SqlClient.SqlDataAdapter(cmdSQL)
        daSQL.Fill(dsTemp)
        Return dsTemp
    Catch sqlEx As SqlClient.SqlException
        'MessageBox.Show("A SQL database error occurred preventing PHOCIS from performing the intended function." + Environment.NewLine + "Function was: " + StoredProcedureName + "." + Environment.NewLine + "Error was: " + sqlEx.Message & Environment.NewLine & "Please contact support for assistance.", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        MessageBox.Show(sqlEx.Message, "Database Error", MessageBoxButtons.OK)
        'MsgBox("There was an error retrieving the data using procedure " & StoredProcedureName & Environment.NewLine & sqlEx.Message, MsgBoxStyle.OkOnly, "Error Loading Data")
        Return Nothing
    Catch ex As Exception
        'MessageBox.Show("An error occurred preventing PHOCIS from performing the intended function." + Environment.NewLine + "Function was: " + StoredProcedureName + "." + Environment.NewLine + "Error was: " + ex.Message & Environment.NewLine & "Please contact support for assistance.", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK)
        'MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error Loading Data")
        Return Nothing
    Finally
        dsTemp = Nothing
        If Not IsNothing(conSQL) Then conSQL.Close()
        cmdSQL = Nothing
        conSQL = Nothing
        daSQL = Nothing
    End Try
End Function

' Missing lots of overloaded procs with name GetInfoInDataset()
clsData调用过程:

''' <returns>3 tables,
''' 1) OSDH_Apps.USERS 
''' 2) OSDH_Apps.USER_DISCIPLINES 
''' 3) OSDH_Apps.USER_MAPPINGS </returns>
Public Function GetAllUserLists() As DataSet
    Try
        Return GetInfoInDataset("GetAllLists")
    Catch ex As Exception
        Return Nothing
    Finally           
    End Try
End Function

frmMain.loadstuff()

Dim userData As DataSet = Nothing
Dim a As New clsData

Try
    userData = a.GetAllUserLists

我不会担心你的英语;这完全可以理解。但更重要的是,你的问题是详细和具体的,你接受所有问题的答案。这比很多人管理的好,谢谢。我知道,数据集是.NET 2.0,但我必须使用.NET 2.0:但是,当我必须单独填充每个表时,我不理解这个生成的dataset类的好处。除此之外,我不知道如何填充这些表。数据集表是强类型的,可以直接绑定到所有asp.net数据控件。请参阅我原始答案中的链接,了解如何填写表格的更好说明!从第一个教程开始。