In this article we will discuss, how to use ExecuteReader() method in ASP.Net c#. When we want to return more than a single value by using ExecuteReader().
protected void Page_Load(object sender, EventArgs e)
//Create the connection object
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ShoppingZone"].ConnectionString); ;
// Pass theconnection to the command object, so the command object knows on which
// connection toexecute the command
SqlCommand cmd = new SqlCommand("Select * from employee", connection);
// Open theconnection. Otherwise you get a runtime error. An open connection is
// required toexecute the command
GridView1.DataSource = cmd.ExecuteReader();
catch (Exception ex)
// HandleExceptions, if any
// The finallyblock is guarenteed to execute even if there is an exception.
// This ensures connections are always properlyclosed.
Post your comments / questions
- How to enable Search Feature in Django admin?
- How to check PAN-Aadhaar is Linked or NOT?
- How to customize pagination for django admin?
- How to fix HAXM is not installed |in Android Studio
- How to fix CMOS Checksum Error in Computer or Laptop | SOLVED
- Reactivating windows after a Hardware change on PC or Laptop
- FIXED: Windows reported that the hardware of your device has changed. Error code :0xc004F211
- "redirect" is not defined pylance("reportUndefinedVariable)