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.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Database ADO.net » DataSet ReadScreenshots 
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.