2007-10-30

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"))

3 comments:

RRave said...

Dear Sir,

I hope you are doing well. I got this email address from one of your contribution web site. I have launched a web site www.codegain.com and it is basically aimed C#,JAVA,VB.NET,ASP.NET,AJAX,Sql Server,Oracle,WPF,WCF and etc resources, programming help, articles, code snippet, video demonstrations and problems solving support. I would like to invite you as an author and a supporter.
Looking forward to hearing from you and hope you will join with us soon.

RRave said...

Dear Sir,

I hope you are doing well. I got this email address from one of your contribution web site. I have launched a web site www.codegain.com and it is basically aimed C#,JAVA,VB.NET,ASP.NET,AJAX,Sql Server,Oracle,WPF,WCF and etc resources, programming help, articles, code snippet, video demonstrations and problems solving support. I would like to invite you as an author and a supporter.
Looking forward to hearing from you and hope you will join with us soon.

Anonymous said...

казино вегас телефон [url=http://blevota6.slot-avtomat.com/doc1250.html]покер счет paypal с карты сбербанка[/url] онлайн покер квест immortal throne, автоматы онлайн покер [url=http://blevota6.slot-avtomat.com]Слоты пополнение qiwi[/url]