Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 15th, 2010  |  syntax: VB.NET  |  size: 1.29 KB  |  hits: 259  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Imports System.Data.SqlClient
  2.  
  3. Module Module1
  4.  
  5.     Sub Main(ByVal sArgs() As String)
  6.  
  7.         Dim SQLStr As String
  8.         Dim ConnString As String
  9.  
  10.         'Connstring = Server Name, Database Name, Windows Authentication
  11.         ConnString = "Data Source=MATHEW-PC\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True"
  12.  
  13.         SQLStr = "SELECT Name from RSSFEEDS"
  14.  
  15.         'Write to SQL
  16.  
  17.         Dim SQLConn As New SqlConnection() 'The SQL Connection
  18.         Dim SQLCmd As New SqlCommand() 'The SQL Command
  19.         Dim SQLdr As SqlDataReader        'The Local Data Store
  20.  
  21.         SQLConn.ConnectionString = ConnString 'Set the Connection String
  22.         SQLConn.Open() 'Open the connection
  23.  
  24.         ' Create Data Adapter
  25.         Dim da As New SqlDataAdapter(SQLStr, SQLConn)
  26.  
  27.         ' Create and fill Dataset
  28.         Dim ds As New DataSet
  29.         da.Fill(ds, "Employee")
  30.  
  31.         ' Get Data Table
  32.         Dim dt As DataTable = ds.Tables("Employee")
  33.  
  34.         'Display Data
  35.         For Each row As DataRow In dt.Rows
  36.             For Each col As DataColumn In dt.Columns
  37.                 Console.WriteLine(row(col))
  38.             Next
  39.         Next
  40.  
  41.         SQLConn.Close() 'Close the connection  
  42.         SQLConn.Dispose()
  43.  
  44.         Console.ReadLine()
  45.  
  46.     End Sub
  47. End Module