Thursday, 29 March 2012

asp.net cookie example: how to create a cookie asp.net cookie example: how to create a cookie

  1. <%@ Page Language="C#" %>  
  2. <%@ Import Namespace="System.Net" %>  
  3.   
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  5.   
  6. <script runat="server">  
  7.     protected void Page_Load(object sender, System.EventArgs e) {  
  8.         HttpCookie userCookie = new HttpCookie("UserInfo");  
  9.         userCookie["Country"] = "Italy";  
  10.         userCookie["City"] = "Rome";  
  11.         userCookie["Name"] = "Jones";  
  12.         userCookie.Expires = DateTime.Now.AddDays(3);  
  13.         Response.Cookies.Add(userCookie);  
  14.         Label1.Text = "Cookie create successful!<br><br/>";  
  15.           
  16.         HttpCookie cookie = Request.Cookies["UserInfo"];  
  17.           
  18.         if (cookie != null)   
  19.         {  
  20.             string country = cookie["Country"];  
  21.             string city = cookie["City"];  
  22.             string name = cookie["Name"];  
  23.             Label2.Text = "Cookie Found and read<br/>";  
  24.             Label2.Text += "Name: " + name;  
  25.             Label2.Text += "<br />Country: " + country;  
  26.             Label2.Text += "<br />City: " + city;  
  27.         }  
  28.     }  
  29. </script>  
  30.   
  31. <html xmlns="http://www.w3.org/1999/xhtml">  
  32. <head runat="server">  
  33.     <title>asp.net cookie example: how to create a cookie</title>  
  34. </head>  
  35. <body>  
  36.     <form id="form1" runat="server">  
  37.     <div>  
  38.         <h2 style="color:Teal">asp.net Cookie example: Create a cookie</h2>  
  39.         <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="SeaGreen">  
  40.         </asp:Label>  
  41.         <asp:Label ID="Label2" runat="server" Font-Size="Large" ForeColor="Crimson">  
  42.         </asp:Label>  
  43.     </div>  
  44.     </form>  
  45. </body>  
  46. </html>   
  47.  

  48.  
  49.  
  50.  
  51.  

Tuesday, 27 March 2012

SQL Tuning/SQL Optimization Techniques

1) The sql query becomes faster if you use the actual columns names in SELECT statement instead of than '*'.

For Example: Write the query as

SELECT id, first_name, last_name, age, subject FROM student_details;

Instead of:

SELECT * FROM student_details;

2) HAVING clause is used to filter the rows after all the rows are selected. It is just like a filter. Do not use HAVING clause for any other purposes.
 

For Example: Write the query as

SELECT subject, count(subject)
FROM student_details
WHERE subject != 'Science'
AND subject != 'Maths'
GROUP BY subject;


Instead of:

SELECT subject, count(subject)
FROM student_details
GROUP BY subject
HAVING subject!= 'Vancouver' AND subject!= 'Toronto';


3) Sometimes you may have more than one subqueries in your main query. Try to minimize the number of subquery block in your query.
 

For Example: Write the query as

SELECT name
FROM employee
WHERE (salary, age ) = (SELECT MAX (salary), MAX (age)
FROM employee_details)
AND dept = 'Electronics';


Instead of:

SELECT name
FROM employee
WHERE salary = (SELECT MAX(salary) FROM employee_details)
AND age = (SELECT MAX(age) FROM employee_details)
AND emp_dept = 'Electronics';


4) Use operator EXISTS, IN and table joins appropriately in your query.
 

a) Usually IN has the slowest performance.
b)
IN is efficient when most of the filter criteria is in the sub-query.
c)
EXISTS is efficient when most of the filter criteria is in the main query.

For Example: Write the query as

Select * from product p
where EXISTS (select * from order_items o
where o.product_id = p.product_id)


Instead of:

Select * from product p
where product_id IN
(select product_id from order_items


5) Use EXISTS instead of DISTINCT when using joins which involves tables having one-to-many relationship.
 

For Example: Write the query as

SELECT d.dept_id, d.dept
FROM dept d
WHERE EXISTS ( SELECT 'X' FROM employee e WHERE e.dept = d.dept);


Instead of:

SELECT DISTINCT d.dept_id, d.dept
FROM dept d,employee e
WHERE e.dept = e.dept;


6) Try to use UNION ALL in place of UNION.
 

For Example: Write the query as

SELECT id, first_name
FROM student_details_class10
UNION ALL
SELECT id, first_name
FROM sports_team;


Instead of:

SELECT id, first_name, subject
FROM student_details_class10
UNION
SELECT id, first_name
FROM sports_team;


7) Be careful while using conditions in WHERE clause.
 

For Example: Write the query as

SELECT id, first_name, age FROM student_details WHERE age > 10;

Instead of:

SELECT id, first_name, age FROM student_details WHERE age != 10;

Write the query as

SELECT id, first_name, age
FROM student_details
WHERE first_name LIKE 'Chan%';


Instead of:

SELECT id, first_name, age
FROM student_details
WHERE SUBSTR(first_name,1,3) = 'Cha';


Write the query as

SELECT id, first_name, age
FROM student_details
WHERE first_name LIKE NVL ( :name, '%');


Instead of:

SELECT id, first_name, age
FROM student_details
WHERE first_name = NVL ( :name, first_name);


Write the query as

SELECT product_id, product_name
FROM product
WHERE unit_price BETWEEN MAX(unit_price) and MIN(unit_price)


Instead of:

SELECT product_id, product_name
FROM product
WHERE unit_price >= MAX(unit_price)
and unit_price <= MIN(unit_price)


Write the query as

SELECT id, name, salary
FROM employee
WHERE dept = 'Electronics'
AND location = 'Bangalore';


Instead of:

SELECT id, name, salary
FROM employee
WHERE dept || location= 'ElectronicsBangalore';


Use non-column expression on one side of the query because it will be processed earlier.

Write the query as

SELECT id, name, salary
FROM employee
WHERE salary < 25000;


Instead of:

SELECT id, name, salary
FROM employee
WHERE salary + 10000 < 35000;


Write the query as

SELECT id, first_name, age
FROM student_details
WHERE age > 10;


Instead of:

SELECT id, first_name, age
FROM student_details
WHERE age NOT = 10;


8) Use DECODE to avoid the scanning of same rows or joining the same table repetitively. DECODE can also be made used in place of GROUP BY or ORDER BY clause.
 

For Example: Write the query as

SELECT id FROM employee
WHERE name LIKE 'Ramesh%'
and location = 'Bangalore';


Instead of:

SELECT DECODE(location,'Bangalore',id,NULL) id FROM employee
WHERE name LIKE 'Ramesh%';


9) To store large binary objects, first place them in the file system and add the file path in the database.

10) To write queries which provide efficient performance follow the general SQL standard rules.
 
a) Use single case for all SQL verbs
b)
Begin all SQL verbs on a new line
c)
Separate all words with a single space
d)
Right or left aligning verbs within the initial SQL verb

Sunday, 25 March 2012

Test Number:6-Topic Name: ADO.NET


.Net Framework and C# Basics - Test No : 01 

 Test Number:2 Topics :Assembly, Event, Delegates_exceptions

Test 04 - Reflection, Custom Attributes, Threading, Windows Service

Test No : 05 -Remoting ,Webservices


Topic Name: ADO.NET


_______ is namespace for  the SQL Server provider classes.
a) Sysytem.Data.Oracle
b)  System.Data.SqlClient
c) System.Data.Sql
d) System.Data.Odbc

_________ contains SQL Server data types.
a)System.Data.SqlserverTypes
b) System.Data.Oralce.Types
c) System.Data.OdbcTypes
d)System.Data.SqlTypes

______ Used as wrappers for SQL statements or stored procedure calls.
a)SqlCommand
b)OracleCommand
c)OleDbCommand and ODBCCommand
d) All the above

A syntax for connection string
a)"Server;datbasename=;uid=id;pwd=pwd"
b)“Server=servername;database=dbName;uid=id;pwd=pwd”
c)"add name=con1 ;databasename=db1 ;connectionstring=con1;uid=id;pwd=pwd"
d) None of the above

Can we directly assign a datareader to a gridview
a)Yes
b)No
d) None of above

________is describes the database instance to connect to; each SQL Server process can
 expose several database instances
a) integrated security = SSPI
b) server=(local)
c) None of above
d) database=Northwind( Any database name) 
______________is Executes the command but does not return any output
a) ExecuteNonQuery()
b) ExecuteScalar()
c) ExecuteReader()
d) None of above
____________is Executes the command and returns a typed IDataReader
a) ExecuteNonQuery()
b) ExecuteReader()
c) ExecuteScalar
d)None of above
______________is Executes the command and returns a single value
a) ExecuteNonQuery()
b) ExecuteReader()
c) ExecuteScalar()
d) None of above

____________is  Executes the command and returns an XmlReader object, which can
be used to traverse the XML fragment returned from the database
a) ExecuteNonQuery()
b) Executescalar()
c) ExecuteXmlReader()
d) None of above

Can we get a XML presentation of a table from Dataset?
a)Yes
b)NO

____________class consists of a set of data tables, each of which will have a set of data columns and data rows
a) Data Adapter
b) DataTable
c)  DataSet
d) DataRow

Data adapter includes _______________command objects
a) Select command
b) insert command
c) update command, delete command
d) All of above
A ___________is very similar to a physical database table — it consists of a set of columns with particular
 properties, and might have zero or more rows of data
a)  dataset
b) data table
c) datacoloumn
d) All of above 

________,______________,_____________ and ________________.Used to generate SQL
 commands (such as INSERT, UPDATE, and DELETE statements) from a SELECT statement
a) SqlCommandBuilder
b) OleDbCommandBuilder,   ODBCCommandBuilder
c) OracleCommandBuilder
d) All of above

  where we should  write a connection string
a) in web.config
b)in App.config file
c) Machine Config
d)all of the above

If we use a DataAdapter, we don’t need to open or close database connection explicitly.
a)Yes
b)No

_________________,________________,__________,________________  Used as a forward only,
 connected data reader
a) OleDbDataReader
b) OracleDataReader
c) SqlDataReader
d)  All of the above

 Which method is used to return the database table in XML format?
a)Serialization format
b) Binary format
c)ReadXML
d)Soap Format
What object is used to generate the commands automatically for a specific SqlDataAdapter?
a) sqlConnection
b) sqlCommandBulider
c) dataset
d) sqlDataReader

Which method  of DataTable can copy all the content from DataReader to DataTable.?
a)Copy
b)Load
c)Unload
d)all of the above
__________ object is designed for disconnected use and can contain a set of DataTables
 and include relationships between these tables
a) Data Adapter
b) system.Data
c) Constraint
d) DataSet 

___________a container of data that consists of one or more DataColumns and, when populated,
will have one or more DataRows containing data
a) DataSet
b) DataTable
c) Datacoloumn
d) DataRow

____________class which represent a number of values, akin to a row from a database table,
 or a row from a spreadsheet
a) DataRow
b) DataColoumn
c) DataAdapter
d) DataTable
______________ object contains the definition of a column, such as the name and data type.
a) DataColoumnMapping
b) DataColumn
c) DataTable
d) DataSet 

_______________a link between two DataTable classes within a DataSet class. Used for foreign
 key and master/detail relationships
a) DataAdapter
b) DataSet
c) Constraint
d) DataRelation
_______________class defines a rule for a DataColumn class (or set of data columns),
such as unique values
a) DataRow
b) Constraint
c) DataTable
d) DataSet 



__________________Maps the name of a column from the database with the name of a
 column within a DataTable.
a) DataTableMapping
b) DataColumnMapping
c) Constraint
d) DataAdapter
______________________ Maps a table name from the database to a DataTable within a DataSet
a) DataColoumnMapping
b) DataTableMapping
c) DataSet
d) DataRow
Namespaces expose the ____________________  used in OLE DB .NET data access.
a) Sqlprovider classes
b) Oracleprovider classes
c) ODBCprovider classes
d)  OLE DB provider classes
________________denotes the database server to connect to. SQL Server permits a number
 of separate database server instances to be running on the same machine, and here you're
connecting to the default SQL Server instance
a) database=Northwind (lets say)
b) integrated security=SSPI 
c) server=(local)
d) None of above

________________ uses Windows Authentication to connect to the database, which is highly
recommended over using a username and password within the source code
a) database=Northwind (lets say)
b) integrated security=SSPI 
c) server=(local)
d) None of above
   Which namespace contains following classes: DataSet, DataTable, DataColumn, and DataRow?
a)System.Data.SqlserverTypes
b)System.data.sqlclient
c) system.data
d)system.configuration

Which object can point to the parameter in stored procedure?
a) parametirsed
b)AddParameter
c)ConnectionParameter
d)Parameter
__________ method executes the command and returns a typed data reader object, depending
 on the provider in use
a) ExecuteNonQuery()
b) ExecuteXmlReader()
c) ExecuteReader()
d) None of Above

______________method is commonly used for UPDATE, INSERT, or DELETE statements,
where the only returned value is the number of records affected
a) ExecuteNonQuery()
b) ExecuteScalar()
c) ExecuteReader()
d) None of Above

In many times, it is necessary to return a single result from a SQL statement, such as the count
 of records in a given table than _________ method is used
a) ExecuteNonQuery()
b) ExecuteScalar()
c) ExecuteReader()
d) None of Above

A ___________ is the simplest and fastest way of selecting some data from a data source,
 but also the least capable
a) Datarecorder
b) Datareader
c) XMLReader
d) All the above

The_______________has been designed as an offline container of data. It has no notion of
 database connections
a)  DataSet class
b) DataAdapter
c) DataTable
d) All of above

A ___________ consists of a set of data tables, each of which will have a set of data columns
 and data rows
a)  DataSet class
b) DataAdapter
c) DataTable
d) All of above
________________property of  DataColumnObject  is true, permits the column to be set to DBNull
a) AllowNull
b) AllowDBNull
c) Null
d) None of above
________________ property of DataColumnObject  defines that this column value is automatically
generated as an incre- menting number
a) AllowIncrement
b) AutoIncrement
c) Increment
d) All of above

________________property of DataColumnObject  defines the initial seed value for an AutoIncrement column
a) None of below
b)  AllowIncrement
c) IncrementSeed
d) AutoIncrementSeed

________________property of  DataColumnObject   defines the step between automatically generated
 column values, with a default of one
a) AllowIncrement
b) AutoIncrement
c) AutoIncrementSeed
d) AutoIncrementStep
________________ property of DataColumnObject can be used for displaying the name of the
 column on screen.
a) ColumnName
b) ColumnMapping
c) Caption
d) All of above
________________property of DataColumnObject can define a default value for a column
a) DefaultValue
b) DataType
c) Current
d) Default
Can we add one SQL Server table and another Oracle table inside a single DataSet?
a)Yes
b)NO
_____________________is datarowstate which indicates that the row has not been changed
 since the last call to AcceptChanges().
a) Original
b) Modified
c) Expression
d) Proposed
_____________________ is datarowstate which  indicates that the row has not been changed
since the last call to AcceptChanges().
a) Added
b) Deleted
c) Depatched
d) Unchanged
_____________________ is datarowstate state which indicates that the row has been newly
added to a DataTable's Rows collection
a) Added
b) Deleted
c) Depatched
d) Unchanged
________________returns an integer representing how many table rows were affected by the query
a) ExecuteNonQuery()
b) ExecuteScalar()
c) ExecuteReader()
d) None of Above
__________- these are the extreamly useful controls to output the data on the web pages
a) All of below
b) Repeater
c) DetailsView, FormView
d) GridView, DataList

All data-bindable controls support  the top- level  ________________ method.
a) Eval()
b) Bind()
c) DataBind()
d) All of above
Changes made to the DataSet need to save on Server, which method helps to do this?
a)Updation
b)Update
c)Updatemethod()
d)update()
The _____________ expression is identical but allows to insert data into attributes of server controls
a) Eval()
b) Bind()
c) DataBind()
d) All of above

Which is a set of operations that must either succeed or fail as a unit?
a)Triggers
b)Sql query
c) Transaction
d)function

What are the 2 methods of DataAdapter, when the connection is open?
a)open connection
b)fill,update
c)fill,open
d)sql connection.open

If we are specifying windows authentication in connection string what element we should add?
a)pool=false;
b)intial integrated=db1;
c)IntegratedSecurity= true
d)None of the above

Which class can be used to implement relationship on client side?
a)Dataset
b)DataRelation
c)DataAdpter
d)DataReader

Which object is used to point location of database?
 a) ConnectionSQlstring
b)ConnectionString
c)ConnectionParameter
d)Connection