不幸的是,您没有提供太多信息,但让我给您一些代码示例,您应该能够根据自己的目的进行修改。
Dim SQL1 As String = "SELECT Field1, Field2 FROM Table1 where Field2 = 7" 'Standard SQL
Dim SQL2 As String = "SELECT Field3, Field4, Field1 FROM Table2 Where Field1 in (SELECT Field1 FROM Table1 where Field2 = 7)" 'This SQL contains a nested select to get the child data for only the records that match the parent
'A neat feature, combine them into 1 SQL statement that will produce 2 tables in your dataset in one call
Dim SQL3 As String = SQL1 & ";" & SQL2
Dim CN As New SqlClient.SqlConnection("Your connection string here")
Dim DS As New DataSet
Dim DA As New SqlClient.SqlDataAdapter(SQL3, CN)
CN.Open()
DA.Fill(DS)
CN.Close()
有关正在发生的事情的解释,请参见代码中的注释。根据您的 VB.net、Sql Server 和 Net1.1 的标签,这应该都适合您。