Reduce Code and Server Roundtrips: Listing 1: C#: Create a Delimited String on the Client
Creating a delimited string on the client is a fairly trivial task using a StringBuilder object. The code simply loops through the selected territories in the ListBox and builds a delimited string, separating column values with "|" and row values with "@@". The delimited string is then passed to the stored procedure as a VARCHAR parameter. The search results are returned from the stored procedure as a DataSet and bound to the grid on the form.
private void btnGetOrdersDelimited_Click(
object sender, EventArgs e)
Cursor.Current = Cursors.WaitCursor;
StringBuilder sb = new StringBuilder();
// build the delimited string containing
// selected territories to pass as a stored
// procedure parameter. Columns are
// separated by "|" and rows are
// separated by "@@"
for (int i = 0; i <
+ "|" + territory.TerritoryName + "@@");
OrdersDS ds =
Cursor.Current = Cursors.Default;