Click here to Skip to main content
15,886,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have connection string like this
VB.NET
Dim sqlConn As New SqlClient.SqlConnection("Data Source=C8067;Initial Catalog=msdb;Integrated Security=True")



This is a local database where i did not specify any schema while creating it.

now i want to retrieve only table names which I created.

I tried this but it retrieves all tables which i do not require like this

VB.NET
Dim cmd As New SqlClient.SqlCommand("select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE'", sqlConn)


Result

syspolicy_policies_internal
sysproxies
sysdbmaintplan_history
backupmediaset
sysdownloadlist
sysjobhistory
backupset
regions

Please help me filter. I want to only tables I created
Posted

1 solution

SQL
SELECT sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U'
 
Share this answer
 
Comments
vivianpinto 11-Jan-16 20:50pm    
Thank you Damit

It gives me the same list even if i comment the sql command querry. this is strange.
Am I wrong in my code at looping.? why it gives me result even if comment the sql querry?

<pre lang="C#">Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim sqlConn As New SqlClient.SqlConnection("Data Source=C8067;Initial Catalog=msdb;Integrated Security=True")
sqlConn.Open()

'Dim cmd As New SqlClient.SqlCommand("SELECT sobjects.name FROM sysobjects sobjects WHERE sobjects.xtype = 'U'", sqlConn)
Dim dsColumns As New DataSet
Dim daAdapter As New SqlClient.SqlDataAdapter(cmd)

daAdapter.Fill(dsColumns)
If dsColumns.Tables(0).Rows.Count > 0 Then
ListBox1.Items.Clear()
For i As Integer = 0 To dsColumns.Tables(0).Rows.Count - 1
ListBox1.Items.Add(dsColumns.Tables(0).Rows(i)(0).ToString())


Next
Else
MessageBox.Show("Tables not found.")
End If
sqlConn.Close()
DamithSL 12-Jan-16 0:30am    
you should get compile error for above code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900