// shared connection and query strings string cn = "server=localhost;uid=sa;pwd=;database=pubs"; string sql = "select au_id, au_lname from authors where au_lname like 'm%' "; string sql2 = "select pub_id, pub_name from publishers where pub_name like '%pub%' "; string sql3 = "select title_id, title from titles where title like '%computer%' ";
// SAMPLE ONE: using FillDataSet with multiple query strings in a single pass
// DataSet ds = new DataSet(); // SqlHelper.FillDataset(cn,CommandType.Text, sql + sql2 + sql3, ds, new string[]{"authors","pubs","titles"}); // lblTableName.Text = ds.Tables[2].TableName.ToString(); // dgtest.DataSource = ds.Tables[2].DefaultView; // See my DAAB, Part 2 post below on updating Sqlhelper.cs to use tablenames, i.e., ds.Tables["titles"].DefaultView;
// SAMPLE TWO: using ExecuteDataSet with multiple sql statements. Returns Table0, Table1, etc.
// lblTableName.Text = SqlHelper.ExecuteDataset(cn, CommandType.Text, sql + sql2).Tables[1].TableName; // dgtest.DataSource = SqlHelper.ExecuteDataset(cn, CommandType.Text, sql + sql2).Tables[1].DefaultView;
// SAMPLE THREE: using ExecuteDataSet with stored procedure and two string param input values
// string lname_initial = "m"; // string state = "CA"; // dgtest.DataSource = SqlHelper.ExecuteReader(cn, "p_authors", new String[]{lname_initial, state});
// SAMPLE FOUR: using ExecuteDataSet with stored procedure and one string param, one integer input values
// string stor_id = "8042"; // int qty = 15; // dgtest.DataSource = SqlHelper.ExecuteReader(cn, "p_sales", new String[]{stor_id, qty.ToString()});
|