ASP.NET C# : Today we are going to see the answers for these questions:
gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg Point No. 1: When to use ExecuteScalar,ExecuteReader and ExecuteNonQuery? It depends on the SQL Statement used in your code. If the output of the sql statement is JUST A SINGLE VALUE, then use : ExecuteScalar. If the output of the sql statement is MORE THAN ONE VALUE then use : ExecuteReader If the output of the sql statement is NONE, then use : ExecuteNonQuery. ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg Point No 2. Can you give some SQL statements which returns JUST A SINGLE VALUE? "Select count(*) from emp" "Select EmpName where EmpID=25 "Select Sum(marks) from MarksMaster where StudentId=25" Note: If your sql statement output has more than one value,ExecuteScalar will return the value of first column of first row. gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg Point No.3 Can you give some SQL statements which returns MORE THAN ONE VALUE? "Select EmpID,EmpName,Salary from emp" "Select * from emp where emp_id=25" gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg Point No. 4: Can you give some sql statements which returns no output data: "Insert into emp values(1,'raja',2000)" "Update emp set EmpName='Raja' where EmpId=25" "Delete from emp where EmpID=25"
Note: ExecuteNonQuery will not return any records. but it will return number of records affected. If "No Count" property of the database is ON, then it will NOT return number of records affected. Instead it will return just -1 (minus one). gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
ExecuteReader EXAMPLE-01 string sConn= "Data Source=SALES;user id=scott;password=tiger;"; gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg ExecuteReader EXAMPLE-02 string sConn= "Data Source=SALES;user id=scott;password=tiger;"; while (myReader.Read()) } gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg ExecuteReader EXAMPLE-03 public void ReadOra()
ExecuteScalar EXAMPLE-01 string sConn= "Data Source=SALES;user id=scott;password=tiger;"; note: ExecuteSclar() will return an object. If you want integer as output, then you should use "int" cast operator as shown above. ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg ExecuteNonQuery EXAMPLE-01 public void DeleteMe() finally ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg ExecuteNonQuery EXAMPLE-02 public void InsertOra()
ExecuteNonQuery EXAMPLE-03 string sConn= "Data Source=SALES;user id=scott;password=tiger;";
ExecuteNonQuery : Example 02 string sConn= "Data Source=SALES;user id=scott;password=tiger;";
|
The things I learnt while I migrated from classic asp to asp.net is given here for my reference as well as for new beginners.
INDEX
-
▼
2009
(17)
-
▼
January
(17)
- The Very First Video Tutorial for ASP.NET C#
- Your First Csharp Code
- PHONE BOOK PROGRAM CODE IN ASP.NET CSHARP
- SINGLE DIMENTIONAL ARRAY C#
- TWO DIMENTIONAL ARRAY C# CODE
- ASP.NET CODING FOR REPEATER CONTROL
- ASP.NET-CSHARP-XML-AS-DATABASE
- LISTBOX LESSON 2 HOW TO MOVE DATA FROM LISTBOX TO ...
- ASP.NET-CSHARP-DROPDOWNLIST-EDIT FORM-SOURCE CODE
- What is AuotEventWireup and how to use it
- How to Create HyperLink in a Data Grid
- Login Form - Code in ASP.NET Csharp
- What is ADO.NET | Data Provider | DataSet
- CSHARP command parameter concepts
- Why @ symbol is used in string
- ExecuteScalar ExecuteReader ExecuteNonQuery : What...
- HASH TABLE VS SCRIPTING DICTIONARY
-
▼
January
(17)
ExecuteScalar ExecuteReader ExecuteNonQuery : What is the Difference
Related Links
Thanks for Your Visit
|
||
| ||
Disclaimer and Copy Right |