0 Comments

The following C# code will query a log table on a Microsoft SQL Server database by using Microsoft ADO .NET 3.5:
        public bool DoesLogTableContainMessage(stringmessage)
        {
            bool result = false;
            using(DataTable dataTable = newDataTable())
            {
                using(SqlConnection connection = newSqlConnection(ConfigurationManager.ConnectionStrings["UnittestDb"].ConnectionString))
                {
                    connection.Open();
                    using(SqlDataAdapter adapter = newSqlDataAdapter("select * from adalog where [message] like ‘test%’", connection))
                    {
                        int rowsAffected = adapter.Fill(dataTable);
                    }
                }
                if(dataTable.Rows.Count > 0)
                    result = true;
            }

            returnresult;
        }

The following C# code will execute a truncate table on a log table on a Microsoft SQL Server database by using Microsoft ADO .NET 3.5:
            using (SqlConnection connection = newSqlConnection(ConfigurationManager.ConnectionStrings["UnittestDb"].ConnectionString))
            {
                connection.Open();
                using(SqlCommand command = newSqlCommand("truncate table adalog", connection))
                {
                    int rowsAffected = command.ExecuteNonQuery();
                }
            }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.