In my previous
article I explained How to upload or Save files in folder and download files when click on
Download link in gridview using asp.net , How to insert images into our project folder and display the images in
gridview using asp.net , How to bind data to Dropdown list in Gridview row databound event , How to implement cascading dropdown list in gridview using asp.net , How to highlight gridview rows on mouseover and on mouseout event .
ASP.NET & C#
Saturday, 26 July 2014
How to execute a stored procedure with Parameters in C# program or How to call stored procedure with Parameters in in asp.net c# code
In this article I will explain How to execute a stored procedure with Parameters in C# program
or How to call stored procedure with Parameters in in asp.net c# code.
In this session I will explain how
establish a connection to sql server and How to execute stored procedure and
How to declare sql command and how to fill sql data adapter code to dataset and
How to pass parameters to Database.
Below
namespaces are for establishing a connection to Sql server.
using System.Data.SqlClient;
using System.Data;
Below is the Database connection string
SqlConnection con = new SqlConnection("server=Localhost;database=DBName;uid=sa1;pwd=g@123;MultipleActiveResultSets=True");
// Use GetRole is a Stored Procedure name
SqlCommand cmd = new SqlCommand("GetRole", con);
cmd.CommandType
= CommandType.StoredProcedure;
//Here
we can add parameter
//Check
syntax of the passing parameters
cmd.Parameters.Add(new SqlParameter("@UserID",
txtUserID.Text));
cmd.Parameters.Add(new SqlParameter("@Password",
txtPassword.Text));
// Use a SqlDataAdapter object to Execute the cmd
SqlDataAdapter daUserData = new SqlDataAdapter(cmd);
//Use
a DataSet object to gather the returned rows
and to work with these rows in addition to the return //values and the return
parameters.
DataSet dsRole = new DataSet();
daUserData.Fill(dsRole);
Friday, 25 July 2014
How to execute a stored procedure within C# program or How to call stored procedure in asp.net c# code
In
this article I will explain How to execute a stored
procedure within C# program or How to call stored
procedure in asp.net c# code In ASP.NET and C#.
In this session I will explain how establish a connection to sql server
and How to execute stored procedure and How to declare sql command and how to
fill sql data adapter code to dataset.
Below
namespaces are for establishing a connection to Sql server.
using System.Data.SqlClient;
using System.Data;
Below is the Database connection string
SqlConnection con = new SqlConnection("server=Localhost;database=DBName;uid=sa1;pwd=g@123;MultipleActiveResultSets=True");
// Use GetRole is a Stored Procedure name
SqlCommand cmd = new SqlCommand("GetRole", con);
cmd.CommandType
= CommandType.StoredProcedure;
// Use a SqlDataAdapter object to Execute the cmd
SqlDataAdapter daUserData = new SqlDataAdapter(cmd);
//Use
a DataSet object to gather the returned rows
and to work with these rows in addition to the return //values and the return
parameters.
DataSet dsRole = new DataSet();
daUserData.Fill(dsRole);
Subscribe to:
Posts (Atom)