none
How to iterate database in SQL server using c#. RRS feed

  • Question

  • I want to iterate database so that i can get all table name present in that database.

    Ajit

    Wednesday, December 20, 2017 1:29 PM

All replies

  • DataSet.Tables Property (System.Data)


    Sam Hobbs
    SimpleSamples.Info

    Wednesday, December 20, 2017 10:13 PM
  • Hi Risu Raj,

    >>I want to iterate database so that i can get all table name present in that database.

    If you only want to retrieve the table names, please refer to thte following code, which stored the names into a List<string>

    string connstr = @"data source=(localdb)\MSSQLLocalDB;initial catalog=EFDemo;integrated security=True";
    List<string> tables = new List<string>();
    using (var conn = new SqlConnection(connstr))
    {
                    
         conn.Open();
         DataTable dt = conn.GetSchema("Tables");
         foreach (DataRow row in dt.Rows)
         {
             string tablename = (string)row[2];
             tables.Add(tablename);
         }
    }

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 21, 2017 1:59 AM
    Moderator