Download sql helper class in c#.net
I have already inserted few records in the table. Note : You can download the database table SQL by clicking the download link below. Download SQL file. First you will need to download the setup file of the Microsoft Data Access Application Block using the following download link.
Once downloaded you will need to install the Setup file. During installation the installer will prompt to choose the installation files location. You need to copy the installation path as it will be needed later to locate the Microsoft. Once the installation is completed, you will need to browse the location copied earlier using Windows Explorer and look for the Microsoft. Net with C and VB. Now we will start exploring the examples of the following SqlHelper class methods.
ExecuteScalar — Fetching single cell value. ExecuteDataset — Fetching DataSet of records. You will need to import the following namespaces. Imports System. Imports Microsoft. It accepts the following 4 parameters. Connection String — Connection string to the database. CommandParameters Optional — Array of Parameters to be passed.
ConnectionStrings[ "constr" ]. Add new SqlParameter " Name" , name ;. Add new SqlParameter " Country" , country ;. ExecuteNonQuery constr, CommandType. Text, query, parameters. ToArray ;. ConnectionStrings "constr". Add New SqlParameter " Name" , name. Add New SqlParameter " Country" , country. End Sub. ExecuteScalar Example with SqlHelper class. ToInt32 SqlHelper. ExecuteScalar constr, CommandType. RegisterClientScriptBlock this.
RegisterClientScriptBlock Me. ExecuteReader Example with SqlHelper class. It returns the SqlDataReader object, which can be used in loop for reading records one by one and also can be directly assigned to a DataSource control. ExecuteReader constr, CommandType. Text, query ;.
DataBind ;. The method has many overloads that you can use to satisfy your needs. The ExecuteDataSet method will be the most commonly used method you will use in your application. Sometimes you have a need to retrieve a single row instead of group of rows. Whenever you need to retrieve a single row you will have to change your stored procedure. I am not saying that this is the only way to referring to a single row since you can retrieve all the rows into a dataset and than pick the row you like.
I am talking about retrieving a single row from the database. Lets see what you need to do in your stored procedure to get one row out of it. As you see in the stored procedure that we have marked the parameters with OUTPUT which means that when the execution of stored procedure is completed those parameters with OUTPUT keyword will be returned to the caller.
Let's now see the C code of how we can use to retrieve a single row. You can perform the same operations in a number of ways. I like it this way since its more clear. As you can see you first created an array of Parameters. You can not only retrieve data from the database but also from any XML File. Lets see a small code sample which shows this operation. The SqlHelper class just makes the Data Access Layer more compact and reusable across various applications.
Sign in Email. Forgot your password? Search within: Articles Quick Answers Messages. Tagged as C. Stats NET Utility. Rakesh S S Rate me:. Please Sign up or sign in to vote. Introduction The Microsoft. Using the code Using the Microsoft. Accessing data without Data Access Application Block: Let's first see how we can access data without using the Application Block so that we can compare the flexibility of both approaches.
Copy Code. Rakesh S S. Ricardo Ribani Sep Ranisz 9-Jan Er Atul Sharma Jul Mujtaba Faizan Jul Rakesh S S Mar Go to top. Layout: fixed fluid. First Prev Next. Thanks for explaining very clearly with each and every code Snippet needed to understand the Concept of Sqlhelper!!! Source Code Ricardo Ribani Sep Ricardo Ribani. I cant't download the code My vote of 3 Ranisz 9-Jan Content under link not found. SQLHelper is a very old tool. Parameter handling is very poor and requires changes in SQLHelper itself to tackle more complex scenarios.
Vote 3 for pushing 10 years old approaches Can i use oraclesqldeveloper instead of sqlserver kingsa Nov NET Utility , it works ornot. My vote of 5 Er Atul Sharma Jul Er Atul Sharma. Mujtaba Faizan. How to insert null values using application block. My vote of 4 nevergiveupc 5-Mar I just want to know if a store procedure should be made before we use the SqlHelper to rechive some data?