Databases Reference
In-Depth Information
from
customers
where
companyname like 'A%'
";
// query 2
string sql2 = @"
select
firstname,
lastname
from
employees
";
// combine queries
string sql = sql1 + sql2;
n Caution Some DBMSs require an explicit character as a separator between multiple queries, but
SQL Server requires only whitespace before subsequent SELECT keywords, which you have because of the
verbatim strings.
The only other change is that you loop through result sets. You nest the loop that
retrieves rows inside one that loops through result sets.
// loop through result sets
do
{
while (rdr.Read())
{
// print one row at a time
Console.WriteLine("{0} : {1}", rdr[0], rdr[1]);
}
Console.WriteLine("".PadLeft(60, '='));
}
while (rdr.NextResult());
We have you choose only two character-string columns per query to simplify things.
Extending this to handle result tables with different numbers of columns and column
data types is straightforward.
Search WWH ::




Custom Search