Search code examples
c#asp.netsql-serverdatabasesqlconnection

How to find the last modifed date and time of a database table


I have get to the point where the connection is open and able to display database name...

using (SqlConnection connection = new SqlConnection("connectionstring_here"))
            {
            try    
            {

            connection.Open();
            DBname.Text=connection.Database;

            } 
            catch (Exception) 
            { 
            /*Handle error*/ 
            }
            }

I see on MSDN that there is this "table" class and its last modified date is tb.DateLastModified.ToString()

How do I get to that given where I get to?


Solution

  • It is SQL Server Management objects.

    1. Add a project reference
    2. Browse to C:\Program Files\Microsoft SQL Server\120\SDK\Assemblies\
    3. Add reference to Microsoft.SqlServer.Smo

    You should now be able to follow the MSDN guidance and use a table object.