locked
SQL reader returns nothing yet no errors and i know the database is full RRS feed

  • Question

  • Hi,

    I'm trying to connect to a remote database using vb.net. I have the following code running:

    Private Sub OpenSourceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenSourceToolStripMenuItem.Click
    
            Dim SQLConnection As System.Data.SqlClient.SqlConnection
    
            Dim SQLCommand As System.Data.SqlClient.SqlCommand
    
            Dim SQLReader As System.Data.SqlClient.SqlDataReader
    
            Dim MyString As String
    
    
    
            SQLConnection = New Data.SqlClient.SqlConnection("SERVER=172.32.10.11;UID=sa;PWD=<removed>;DATABASE=test")
    
    
    
            Try
    
                SQLConnection.Open()
    
                SQLCommand = New Data.SqlClient.SqlCommand("SELECT * FROM Station", SQLConnection)
    
                MsgBox(CStr(SQLCommand.ExecuteNonQuery))
    
                SQLReader = SQLCommand.ExecuteReader
    
                While SQLReader.Read
    
    
    
                End While
    
                MyString = String.Empty
    
                For Each element In SQLReader
    
                    MyString = MyString & " - " & element.ToString
    
                Next
    
                MsgBox(MyString)
    
                SQLReader.Close()
    
                SQLConnection.Close()
    
    
    
            Catch ex As Exception
    
                MsgBox(ex.Message, MsgBoxStyle.Critical, "Hey!")
    
            End Try
    
        End Sub

    Connection works ok, if i omit the database parameter "test" the selected database is then "master" (unless that's the objects standard :S)

    Now when i execute this script there are no errors or warnings at all, but also there is no return information. The database is created on the other computer using OSQL with SQL 2000. The test database has a table Station, with collums id, name, lastname. I also filled the first row with my own name.

    What could be the reason that i cannot get the return of my own name?

    Greetings,

    CrashPilot

    Thursday, March 25, 2010 3:30 PM

Answers

  • Solved the problem, silly mistake in the sourcecode. The string buildup routine should obviously be in the While loop of the SQLReader.Read().
    • Marked as answer by CrashPilot Thursday, April 8, 2010 1:14 PM
    Wednesday, March 31, 2010 8:21 AM