Hi,
Guys I have a problem in ADO.NET. What is Command object in ADO.NET and how to use it with data adapter..
Thank You....
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Prabhu RajaPosted Sep 26, 2011, 1:26 AM
About Command Object :
Command objects are used to perform data manipulation inside of sql server (Backend) from .net(Front End).
Using Command objects, we can Execute our Sql Query's Like Insert,update,delete and Select etc. Also We Execute Procedures.
Also We can pass parameters to procedures.
About Data Adapters:
Data Adapters having set of objects to communicate with data source and dataset.
For example:
-------------------------------------------------------------------
If this post helps you, then mark as "Correct Answer"
Thank You
Prabhu Raja
Satyapriya NayakPosted Sep 26, 2011, 12:53 AM
Command object:-A database command specifies which particular action you want to perform to the database. The commands are in the form of SQL (Structured Query Language).
DataAdapter :-A class that connects to the database system, fetch the record and fill the dataset. It contains four different commands to perform database operations; Select, Update, Insert, Delete.
ex:- Login form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Login_Form_in_Csharp_Using_ProgressBar
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void btnlogin_Click(object sender, EventArgs e)
{
if (txtusername.Text == "" || txtpassword.Text == "")
{
MessageBox.Show("Please enter User ID or Password");
txtusername.Text = "";
txtpassword.Text = "";
}
else
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select count(*) from login where userid='" + txtusername.Text.Trim() + "' and password='" + txtpassword.Text.Trim() + "'";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "login");
long x;
x = Convert.ToInt64(com.ExecuteScalar());
if (x == 1)
{
Form2 f1 = new Form2();
f1.Show();
this.Hide();
}
else
{
MessageBox.Show("Invalid User ID or Password! Try Again!");
txtusername.Text = "";
txtpassword.Text = "";
}
con.Close();
}
}
}
}
Thanks
If this post helps you mark it as answer