Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 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
Introduction:

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

Description:

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

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


ExecuteScalar

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


ExecuteReader

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 Asp.net, C#.net, 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

3 comments :

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;
ListBox1.Items.Remove(li);
li.Selected = false;
ListBox2.Items.Add(li);
}
}

protected void Button2_Click(object sender, EventArgs e)
{
if (ListBox2.SelectedItem != null)
{
ListItem li = ListBox2.SelectedItem;
ListBox2.Items.Remove(li);
li.Selected = false;
ListBox1.Items.Add(li);
}
}

//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 C#.net language.

Give your Valuable Comments

Other Related Posts

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