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. |
|||
|
|||
3 comments :
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);
//}
}
}
Very insightful!
I do not really understand the C#.net language.
Note: Only a member of this blog may post a comment.