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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 25, 2011, 8:53 PM EDT
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
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 25, 2011, 9:26 PM EDT
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