Solved

DataSet using Code

Posted on 2008-10-07
2
248 Views
Last Modified: 2010-04-23
DataSet using Code
0
Comment
Question by:JPTenore
  • 2
2 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22657429
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 22657434
A complete example to connect to the database, fill a dataset and loop through that dataset
(console-applicatoin)
Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.Data.SqlClient
 
 
Public Class MainClass
    Shared Dim WithEvents con As SqlConnection
 
    Shared Sub Main()
        con = New SqlConnection("Server=(local)\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI") 
 
        ' Create the command object
        Dim str As String = "SELECT ID, FirstName, LastName FROM Employee"
        Dim cmd As New SqlCommand(str, con)
 
        Dim da As New SqlDataAdapter(cmd)
 
        Dim ds As New DataSet()
 
        da.Fill(ds, "Employee")
 
        Dim dc As DataColumn
        For Each dc In ds.Tables(0).Columns
            Console.Write("{0,15}", dc.ColumnName)
        Next
 
        Console.Write(vbCrLf)
 
        Dim dr As DataRow
        For Each dr In ds.Tables(0).Rows
            Dim i As Integer
            For i = 1 To ds.Tables(0).Columns.Count
                Console.Write("{0,15}", dr(i - 1))
            Next i
            Console.Write(vbCrLf)
        Next
    End Sub
End Class

Open in new window

0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question