Multiple Tables in DataSet : DataSet Read « Database ADO.net « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net » Database ADO.net » DataSet Read 




Multiple Tables in DataSet
  

Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Data

Public Class Form1
    Inherits System.Windows.Forms.Form
    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        Me.Button1.Location = New System.Drawing.Point(9648)
        Me.Button1.Size = New System.Drawing.Size(27240)
        Me.Button1.Text = "Do"
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(456142)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1})
        Me.ResumeLayout(False)

    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button1.Click
        Dim MyDataSet As New DataSet()
        Dim Tables(2As String
        Tables(0"authors" : Tables(1"sales" : Tables(2"titles"
        MyDataSet = GetDataSet("data source=localhost;initial catalog=pubs;user id=sa;pwd=", Tables)
    End Sub

    Public Function GetDataSet(ByVal ConnectionString As String, ByRef Tables() As StringAs System.Data.DataSet
        Dim objConn As New System.Data.SqlClient.SqlConnection(ConnectionString)
        Dim objCmd As New System.Data.SqlClient.SqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = System.Data.CommandType.Text
        Dim objDS As New System.Data.DataSet()

        Dim objDA As New System.Data.SqlClient.SqlDataAdapter(objCmd)
        objDA.SelectCommand = objCmd
        objConn.Open()
        Dim intCount As Integer
        For intCount = To Tables.GetUpperBound(0)
            objCmd.CommandText = "SELECT * FROM " & Tables(intCount)
            objDA.Fill(objDS, Tables(intCount))
        Next
        objConn.Close()
        Return objDS
    End Function
End Class

   
    
  














Related examples in the same category
1.Populate Data from data tablePopulate Data from data table
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.