Solved

DataSet using Code

Posted on 2008-10-07
2
249 Views
Last Modified: 2010-04-23
DataSet using Code
0
Comment
Question by:JPTenore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with preventing downloading a zip file 10 49
vb.net class 3 29
Data organization issue 7 37
Get sourcecode path 14 46
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…

756 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