Get the list of all tables in a database using C#

You want to get names of all tables of SQL Server database in your C# application. Is It possible? Yes you can do this. SqlConnection con = new SqlConnection(ConnectionString); con.Open(); SqlCommand com = new SqlCommand(); com.Connection = con; com.CommandType = CommandType.Text; com.CommandText = "exec sp_tables"; List<string> listTables = new List<string>; SqlDataReader reader = com.ExecuteReader(); if …

Continue reading Get the list of all tables in a database using C#

List all databases on a SQL server and bind to a dropdown list

SqlConnection con = new SqlConnection("server=server;uid=username;pwd=password");                     con.Open();                      SqlCommand com = new SqlCommand();                      com.Connection = con;                      com.CommandType = CommandType.StoredProcedure;                      com.CommandText = "sp_databases";                      SqlDataReader reader = com.ExecuteReader();                      while (reader.Read())                                 ddlDatabases.Items.Add(reader.GetString(0));                  con.Close(); Note that this is not the only method to to do this.