Will this code work in SQL 2005 AND SQL 2008?

Discussion in 'C#' started by JEP_Dude, Dec 28, 2009.

  1. #1
    Hey there....!

    PLEASE HELP! This is the first time I use SQL to read in data! I want to retrieve the entire SQL file into an array.

    If possible, I'd like ti to work for both SQL 2005 and 2008. Is that possible for a SQL novice!

    Imports System.Data.SQLClient

    Private Sub GetDataFromSQLFile ()
    Dim DR As SQLDataReader
    Dim N As String = Nothing
    Dim DQ As String = "SELECT * FROM StockStatus ORDER BY StockSymbol"
    Dim DCommand As New SQLCommand (DQ, SQLConnection1)
    Dim R(15) As String
    Dim Index As Integer = 0

    SQLConnection1.Open()
    DR = DCommand.ExecuteReader

    While DR.Read()
    For Index = 1 to 15
    R(Index) = DR.GetString(Index)
    Next Index
    End While

    DR.Close()
    SQLConnection1.Close
    Exit Sub <--- The book I use has this line. Why is it here?

    End Sub

    God Bless

    JEP_Dude
     
    JEP_Dude, Dec 28, 2009 IP
  2. urstop

    urstop Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yeah, the code will work with both version of SQL. I don't think you need the Exit Sub line of code there as it does not make any sense as it is placed at the end of the procedure.
     
    urstop, Jan 2, 2010 IP