Database Reference
In-Depth Information
3)
{
4)
DataTable dt = ExecuteSingleQuery(command, c, exceptions);
5)
lock (data)
data.Merge(dt, true, MissingSchemaAction.Add);
7) }
8) );
The following code is a simplified version of the actual sample application. (For clarity, some code
that calculates execution time and performs exception handling has been removed.) Line 4 sets the
command text to be executed, such as a SELECT statement, and line 5 executes it against the shard.
Instead of calling ExecuteReader , the code calls ExecuteShardQuery to use the shard. Line 7 binds the
resulting DataTable and displays the records returned by the shard:
1)
6)
SqlCommand cmd = new SqlCommand();
2)
DataTable dataRes = new DataTable();
3)
4)
cmd.CommandText = this.textBox1.Text;
5)
dataRes = cmd.ExecuteShardQuery();
6)
7) dataGridView2.DataSource = dataRes;
Figure 10-5 shows the outcome of this code. The SELECT statement is designed to return database
object names and types. Executing the statement against the shard performs as expected. However,
notice that an extra column has been added to the display: __guidDB__. This is the name of the GUID
column introduced previously. This column doesn't help much for reading, but it enables updates and
deletes, as you see later.
Figure 10-5. Showing records returned by the shard
The GUID provided is unique for each database connection, as long as one of the key parameters is
different in the connection string of each connection. It's added by the ExecuteSingleQuery method
Search WWH ::




Custom Search