Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DataSet using Code

Posted on 2008-10-07
2
Medium Priority
?
254 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

886 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