I spoke at the Plano DNUG last night and had a pretty good time. Basically I presented some information on interfaces, talked about the interfaces in System.Data, discussed what happens behind the scenes with SqlConnection.Close() and SqlConnection.Dispose(), presented issues with creating a data layer, then some discussion on the DAAB. One of the things I didn't show in the meeting last night is how you would deal with parameters. It is a little different. First off, how about a link to my files? :-)
Presentation Files
So, here is a code snip for executing a command on a SQL Server database:
using(DbHelper db = new DbHelper(Configuration.ConnectionString, DbLibrary.SqlClient, true))
{
IDbDataParameter prmDiv = db.GetDbDataParameter("@division", DbType.Int16);
prmDiv.Value = System.Int16.Parse(this.ddlDivisions.SelectedItem.Value);
IDbDataParameter prmOrgStore = db.GetDbDataParameter("@original_store_num", DbType.Int32);
prmOrgStore.Value = System.Int32.Parse(orgStore);
IDbDataParameter prmTrgStores = db.GetDbDataParameter("@target_store_num_xml", DbType.AnsiString);
prmTrgStores.Value = xml.InnerXml;
IDbDataParameter prmExecutingLoginId = db.GetDbDataParameter("@executing_login_id", DbType.AnsiString, 20);
prmExecutingLoginId.Value = EM.Web.Configuration.WebUserId;
db.ExecuteNonQuery(CommandType.StoredProcedure
, spStorePlanCopy, prmDiv, prmOrgStore, prmTrgStores, prmExecutingLoginId);
}
This means that instead of using things like SqlDbType you are using the base DbType instead.
Something that I don't have in this [and that I want] is Parameter Caching. That would be great, but I opted to not put that in here for now. Why? Because I'd rather examine the Microsoft DAAB a little closer to see if there are some other ways to accomplish that. Also, not every provider/driver accepts parameterized sql statements (at least with some of the things I have developed before). So, before I add it in, I wanted to make sure that I do the right things with it. That could mean some sql statement parsing, so I wanted to let that go until later.
So, if you download my presentation, at a minimum check out the DataAccess project. That was the meat and potatoes of this presentation. Let me know what you think!