Rabu, 21 Desember 2011

SQL Helper Class

Microsoft .net framework consists of ADO .NET which enables the developer to interact with the database. ADO .NET provides many rich features that can be used to retrieve and display data in a number of ways. Apart from the flexibility provided by the ADO .NET, sometimes we find ourselves repeating the same code again and again. Consider that at some point in our application we need to pass some parameters and retrieve some information from the database. We can perform this task by writing 5-6 lines of code which is cool. But when later we need to pass the parameters we have to write those 5-6 lines again which is not cool.

Methods

  • ExecuteDataset Retrieve multiple rows from the database and return value to DataSet class.
  • ExecuteNonQuery Executes a Transact-SQL statement against the connection and returns the number of rows affected
  • ExecuteNonQueryReturn No return value.
  • ExecuteReader Retrieve multiple rows from the database and return value to SqlDataReader class.
  • ExecuteScalar Retrieve a single row instead of group of rows and return value to object.
  • ExecuteXmlReader Sends the CommandText to the Connection and builds an XmlReader object.

Summary
  • It is used for Database Access other than System.Data.SqlClient or System.Data.Oledb
  • SqlHelper() - This method used to reduce the lines of connecting the database than when we are using the SqlDataAdapter or OleDbAdapter.
  • You can download sql helper dll at this

Sample Code

' Very short command
Dim nResult as integer
nResult = Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, CommandType.Text, "Select Count(id) from table"))

SQL Helper Class Rating: 4.5 Diposkan Oleh: dragon
Terima kasih sudah berkomentar