When I executed the query below in SSMS, the table names in 'MyDataBase' database were returned correctly. However, when I ran the same SQL command in a VB application using a SqlDataReader, no error but no table names were returned either. Any idea? Thanks!
SELECT [TABLE_NAME] FROM [MyDataBase].[INFORMATION_SCHEMA].[TABLES];
VB code:
Dim cmdTxt As String = "SELECT [TABLE_NAME] FROM [MyDataBase].[INFORMATION_SCHEMA].[TABLES];"
Using conn As New SqlConnection(conString)
Dim cmd As New SqlCommand(cmdTxt, conn)
Dim reader As SqlDataReader
Try
conn.Open()
reader = cmd.ExecuteReader
While reader.Read()
Dim name = reader.GetString(0)
Me.cboTableNames.Items.Add(name)
End While
reader.Close()
Catch ex As Exception
Module1.WriteErrorLog("FormViewData.GetTableNameList(): ", ex.Message)
frmMain.StatusUpdate("Error occured while obtaining list of table names. Reason: " & ex.Message, True)
End Try
End Using