wtorek, 20 maja 2014

Run multiple SQL command in single SQL connection


Execute many sql command in one connection:

 
            using (DbConnection cnn = new SqlConnection(connectionString))
            {
                cnn.Open();
 
                using (DbCommand command = cnn.CreateCommand())
                {
                    command.CommandText = "Select * from sys.tables";
 
                    using (DbDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string tableName = (string)reader["name"];
                        }
                    }
 
                    command.CommandText = "Select * from sys.columns";
 
                    using (DbDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string columnName = (string)reader["name"];
                        }
                    }
                }
            }
 

Brak komentarzy:

Prześlij komentarz