Got more questions? Find advice on: ASP | XML | Regular Expressions | Windows
in Search
Welcome to SqlAdvice Sign in | Join | Help

The Penton-izer

I have moved to http://pentonizer.com so join me there!!!

More on Interfaces and ADO.Net

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!

Sponsor
Published Thursday, June 03, 2004 10:28 AM by dpenton

Comments

 

dpenton said:

David,
Nice Job! I have been looking at the examples and they are great! This is a nice addition too.
June 5, 2004 11:21 AM
 

TrackBack said:

Take Outs for 3 June 2004
June 4, 2004 3:13 AM
 

TrackBack said:

June 4, 2004 6:09 PM
Anonymous comments are disabled