Share Pastebin
Guest
Private paste!

Untitled

By: a guest | Apr 15th, 2010 | Syntax: VB.NET | Size: 1.29 KB | Hits: 276 | Expires: Never
Copy text to clipboard
  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.         SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command
  25.         SQLCmd.CommandText = SQLStr 'Sets the SQL String
  26.         SQLdr = SQLCmd.ExecuteReader 'Gets Data
  27.  
  28.         While SQLdr.Read() 'While Data is Present        
  29.             Console.WriteLine(SQLdr("Name")) 'Show data in a Message Box
  30.         End While
  31.  
  32.         'Loop While SQLdr.NextResult() 'Move to the Next Record
  33.         SQLdr.Close() 'Close the SQLDataReader        
  34.  
  35.         SQLConn.Close() 'Close the connection  
  36.         SQLConn.Dispose()
  37.  
  38.         Console.ReadLine()
  39.  
  40.     End Sub
  41. End Module