aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

ExecuteReader ExecuteNonQuery ExecuteScalar Examples in Asp.NET when to use what to use in C#.NET,VB.NET

Sep 21, 2012

In this article I will explain executereader executenonquery executescalar examples when to use what in using and VB.NET.


If you want to know which command object needs to be used in different situations for that you need to check this article

If you want to know about each sqlcommand object check below articles


ExecuteNonQuery method will return number of rows effected with INSERT, DELETE or UPDATE operations. For more details check this article


Execute Scalar will return first row first column value i.e. it will return single value and ignore other values on execution of SQL Query or Stored procedure using command object.
For more details check this article


Execute Reader will be used to return the set of rows, on execution of SQL Query or Stored procedure using command object. For more details check this article

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...

namespace example1
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
string cs = "server=CHANDANA;database=chandana;Uid=sa;Password=sa123";

SqlConnection con = new SqlConnection(cs);

string com = "Select FirstName,MiddleName,LastName from emply";

SqlDataAdapter adpt = new SqlDataAdapter(com, con);

DataSet myDataSet = new DataSet();

adpt.Fill(myDataSet, "emply");

DataTable myDataTable = myDataSet.Tables[0];

DataRow tempRow = null;

foreach (DataRow tempRow_Variable in myDataTable.Rows)

tempRow = tempRow_Variable;

ListBox1.Items.Add((tempRow["FirstName"] + " (" + tempRow["MiddleName"] + ")" + " (" + tempRow["LastName"] + ")"));

protected void Button1_Click(object sender, EventArgs e)
if (ListBox1.SelectedItem != null)
ListItem li = ListBox1.SelectedItem;
li.Selected = false;

protected void Button2_Click(object sender, EventArgs e)
if (ListBox2.SelectedItem != null)
ListItem li = ListBox2.SelectedItem;
li.Selected = false;

//protected void Button3_Click(object sender, EventArgs e)
// ListBox1.Items.Add(TextBox1.Text);


victoria said...

Very insightful!

submit said...

I do not really understand the language.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.