C# ASP.NET ADO.NET JAVASCRIPT JQUERY AJAX SILVERLIGHT WPF
C# OOPS HTML&CSS DHTML ASP.NET ADO.NET JAVASCRIPT JQUERY AJAX SILVERLIGHT MVVM WPF SQL SERVER Photoshop Dreamweaver Flash Illustrator
Blog Archive
-
2012
(83)
- September(2)
-
August(81)
- Important WPF Classes and Namespaces
- Applications of WPF
- Programming With WPF
- Limitations of Silverlight and flash
- Silverlight Feature comparison with Flash Features
- How to Add XML File in Your Silverlight Project
- 3 Pixel Shader Effects in Silverlight
- Rotate Image in 3D direction using Silverlight
- First Application of Silverlight
- Silverlight 2.0
- How Install Ajax?
- Ajax Advantage
- JavaScript Loops
- Show a Military Clock and ordinary clock
- How To validate a Form in ASP. Net
- How to show Day of Week
- How to Swap a Image using JavaScript
- Special Character in JavaScript
- Prompt Box in JavaScript
- The use of data adapter.?
- The steps involved to fill a dataset?
- Dataset object in ADO .NET
- Handling Connection Events
- The SQLCONNECTION OBJECT
- Command Constructors
- The SQLCOMMAND OBJECT
- Gridview in ASP.NET
- Introduction Of Master Page
- Server Side State Management
- Query String In ASP.NET
- Cookies in ASP.NET
- State Management in ASP.NET
- Various types of application that we can develop i...
- Properties
- Inheritance ,Polymorphism
- Array,Indexer and Collections
- Control Statements
- Operators, types and variables in C#
- Fundamental of C#
- C# & other Programming Languages
- The WPF Designer
- C# DataTypes
- What is Ajax?
- Silverlight 1.0
- Confirm Box in JavaScript
- Component classes
- Life Cycle of ASP.NET
- The Basics of JQuery
- Jquery Blog Content
- Birth Of WPF
- .Net Frameworks Architecture
- History Of Ajax
- Why Silverlight?
- How to access a URL of parent page in ASP. net
- THE ADO.NET Architecture?
- Architecture of ASP.NET
- Introduction Of Ajax
- Ajax Blog Content
- Introduction of SilverLight
- Silverlight Blog Content
- Introduction to Javascript Blog
- Javascript Blog Content
- Introduction to Ado.Net blog
- Ado.Net Blog Content
- Introduction to C# Blog
- C# Blog Content
- Introduction to Asp.Net
- Asp.Net Blog Content
- Introduction to WPF
- WPF Blog Content
- WPF Interview Question
- Silverlight Interview Question
- Ajax Interview Question
- JQuery Interview Question
- Javascript Interview Question
- DHTML Interview Question
- Ado.Net Inetview Questions
- SQL Interview Questions
- HTML&CSS Interview Questions
- Asp.Net Interview Qusetions
- C# Interview Questions
The SQLCOMMAND OBJECT
The SQLCOMMAND OBJECT
When we have a more complex query that retrieves records from different tables, or don't want the UPDATE command to check for changes in the database before updating it, we can specify our own SQL commands.The Command object enables to execute queries against data source. in order to retrieve data, you must know the schema of your database as well as how to build a valid SQL query. The Command objects allow developers to specify parameters dynamically at run time. When defining the SQL statement we use a placeholder instead of a particular value. Then we use the Parameters collection of the Command object to define the dynamic column value.The SqlCommand object must be used in conjunction with the SqlConnection object
Creating a SqlCommand Object
SqlCommand cmd = new SqlCommand("select CategoryName from Categories", new sqlconnection(parameter));
Querying Data
using a SQL select command
1)Instantiate a
new command with a query and connection
SqlCommand cmd = new
SqlCommand("select EmployeeName from Emp", conn);
2. Call Execute reader to get query
results
SqlDataReader dr = cmd.ExecuteReader();
Inserting Data
using a SQL insert command,To insert data into a database, use the ExecuteNonQuery method of the SqlCommand object.
1)Insert command
string
string
insertString = @"
insert into Emp
(EmpName, Post)
values ('Aditya', 'S\w Engg')";
2.)Instantiate a new command with a query
and connection
SqlCommand cmd =
new SqlCommand(insertString, conn);
3) Call ExecuteNonQuery to send command
cmd.ExecuteNonQuery();
Updating Data
using a SQL update command,To update data into a database, use the ExecuteNonQuery method of the SqlCommand object.
1)prepare
command string
string updateString = @"
update Emp
set EmpName = 'Ashish'
where CategoryName = 'Raj'";
2) Instantiate a new command with command text only
SqlCommand cmd = new
SqlCommand(updateString,conn);
3) Call ExecuteNonQuery to send command
cmd.ExecuteNonQuery();
Deleting Data
using a SQL delete command,To delete data into a database, use the ExecuteNonQuery method of the SqlCommand object.
1)
delete command string
string deleteString = @"
delete from Emp
where EmpName = 'Ashish'";
2) Instantiate a new command
SqlCommand cmd = new SqlCommand();
3) Set the CommandText property
cmd.CommandText = deleteString;
4) Set the Connection property
cmd.Connection = conn;
5)Call ExecuteNonQuery to send command
cmd.ExecuteNonQuery();
Getting Single Values
For getting a single value we can use count, sum, average, or other aggregated value from a data set.
1)
Instantiate a new command
SqlCommand cmd = new
SqlCommand("select count(*) from Categories", conn);
2) Call ExecuteNonQuery to send command
int count = (int)cmd.ExecuteScalar();









