Hey geeks,Well ... It is always difficult to understand someone's code which you have writted already. I have written a Library called Data Aceess Tools, which is more like a data block of enterprise library. However, enterprise library is quit advance then Data Aceess Tools, which make my interest to work on enterprise library. so let me give you step by step instrucion. now please dont ask me to define the installations step thats too simple, we have been doing the same installation from childhood. so lets get down to the business.Step 1 (Adding Enterprise Library to Project):
Geeks, before I start I would like to remind again that this article is will provide only Data Block information that is why we need to register two dlls in out project.1) Microsoft.Practices.EnterpriseLibrary.Data.Sql & Microsoft.Practices.EnterpriseLibrary.Data.Yes, It is sure very easy. so lets move on.Step 2 (Coding):
first of all import the foloowing libraries in the class
Imports Microsoft.Practices.EnterpriseLibrary.Data.SqlImports Microsoft.Practices.EnterpriseLibrary.Data
Now for creating the connection, Create Database object and pass the connection String in the method.
Dim db As Database = DatabaseFactory.CreateDatabase("Database")
Well in our case we are trying to access Stored procedure, so lets start with that.
Dim DbCommand As Common.DbCommand = db.GetStoredProcCommand(“Sp_writeData“)
now lets add parameters for stored procedure.
db.AddInParameter(DbCommand, "@UserID", DbType.Int32, reportId)db.AddInParameter(DbCommand, "@Age", DbType.Int32, reportJobId)db.AddInParameter(DbCommand, "@MisInfo", DbType.Xml, parameterXml)
Okay let me define these lines. db is the name of database object by which we are adding parameters. DbCommand is the name of command Object in which we are adding parameters.Now if this stored procedure returning you result then do the following:
Dim dr as SqlClient.SqlDataReader = db.ExecuteReader(DbCommand)
Dim ds as DataSet = db.ExecuteDataSet(DbCommand).
here it is , now you got the result in your recordset ..... do whatever you want to . (with database) :)