
December 29th, 2008

admin
SELECT INTO statement can be used to create backup copy of a table.This sql statement selects records from one table according to the selection we make and inserts the result set into another new table with the table name we specify.
Syntax given below is used to make a exact copy of the table.That is it creates the table with the same no of columns and all records in the old table.
Syntax : Exact copy of old table
SELECT *
INTO new_table_name
FROM old_table_name
Example :
select * into employee_backup from employee
In this example a exact copy of the table employee is backed up as a new table employee_backup.
Syntax given below is used to make a new table with selected columns from old table.
Syntax : Selected columns from old table
SELECT column_name(s)
INTO new_table_name
FROM old_table_name
Example :
select employee_id,employee_name into employee_backup from employee
In this example a copy of the table employee with only columns “employee_id,employee_name” is backed up as a new table employee_backup.
Popularity: 11% [?]

December 22nd, 2008

admin
How to Open a File in Different Format
1.Create a HTML Page or JSP Page
2.Insert <%@ page contentType=”application/vnd.ms-excel” %> instead of <%@ page contentType=”application/html” %> in HTML Page or JSP Page
3.Open a File,Now its open in a Excel Sheet with Style apply in the Sheet.
For Microsoft Word
<%@ page contentType=”application/vnd.msword” %>
For PDF File
<%@ page contentType=”application/vnd.pdf” %>
For Wordpad
<%@ page contentType=”application/vnd.rtf” %>
For Microsoft Powerpoint
<%@ page contentType=”application/vnd.ms-powerpoint” %>
For Winzip
<%@ page contentType=”application/vnd.zip” %>
Popularity: 2% [?]

December 16th, 2008

admin
Reduce network traffic: You have to send the SQL statement across the network. With sprocs, you can execute SQL in batches, which is also more efficient.
Caching query plan: The first time the stored procedure is executed, SQL Server creates an execution plan, which is cached for reuse. This is particularly performant for small queries run frequently.
Ability to use output parameters: If you send inline SQL that returns one row, you can only get back a recordset. With stored procedures you can get them back as output parameters, which is considerably faster.
Permissions: When you send inline SQL, you have to grant permissions on the table(s) to the user, which is granting much more access than merely granting permission to execute a stored procedure
Separation of logic: Remove the SQL-generating code and segregate it in the database.
Ability to edit without recompiling: This can be controversial. You can edit the SQL in a sproc without having to recompile the application.
Find where a table is used: With stored procedures, if you want to find all SQL statements referencing a particular table, you can export the stored procedure code and search it. This is much easier than trying to find it in code.
Optimization: It’s easier for a DBA to optimize the SQL and tune the database when stored procedures are used. It’s easier to find missing indexes and such.
SQL injection attacks: Properly written inline SQL can defend against attacks, but stored procedures are better for this protection.
Popularity: 1% [?]

December 12th, 2008

admin
Here in this example we browse a file from our pc and upload that file to some other location in our pc.
Default.aspx
<input type=file id=File1 name=File1 runat=”server”>
<input type=”submit” id=”Submit1″ value=”Upload” runat=”server” name=”Submit1″>
Defalut.aspx.cs
protected void Submit1_ServerClick(object sender, EventArgs e)
{
if( ( File1.PostedFile != null ) && ( File1.PostedFile.ContentLength > 0 ) )
{
string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
//Create Data Folder within the Location u Specified
string SaveLocation = “D:\UploadedFiles” + “\” + fn;
//File will be Uploaded to the Specified Location
try
{
File1.PostedFile.SaveAs(SaveLocation);
Response.Write(“The file has been uploaded.”);
}
catch ( Exception ex )
{
Response.Write(“Error: ” + ex.Message);
}
}
else
{
Response.Write(“Please select a file to upload.”);
}
}
You can give the specified location to upload in SaveLocation string.
Download
Popularity: 2% [?]

December 9th, 2008

admin
Here is a example application of Add,Edit,Retrieve and Delete operations using Asp.net. Download Creating a table employeeinfo for proceeding the operations. Sql Table Creation
CREATE TABLE employeeinfo ( empid INT NOT NULL PRIMARY KEY, empname VARCHAR(50), empaddress VARCHAR(200), empsalary INT )
Declaring Connection String and Variables
Namespace : using System.Data.SqlClient; string QryStr = ""; SqlConnection con = new SqlConnection("Server=servername;Integrated Security=true;Database=employee"); SqlCommand cmd; SqlDataReader dr;
In this example i have used windows authentication.You have to change the connection string according your specification. Adding Records
QryStr = "INSERT INTO employeeinfo VALUES('" +txtEmpId.Text + "','" + txtEmpName.Text + "','" + txtEmpAdd.Text + "','" + txtEmpSal.Text + "')"; con.Open(); cmd = new SqlCommand(QryStr, con); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); con.Close();
Updating Records
QryStr = "UPDATE employeeinfo SET empname = '"+txtEmpName.Text+"',empaddress = '"+txtEmpAdd.Text+"',empsalary = '"+txtEmpSal.Text+"' WHERE empid = '"+txtEmpId.Text+"'"; con.Open(); cmd = new SqlCommand(QryStr, con); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); con.Close();
Retrieve Records to textboxes Records will be Retrieved from the database and displayed in the text boxes when text change of employee id is fired.
QryStr = "SELECT * FROM employeeinfo WHERE empid = '" + txtEmpId.Text + "'"; con.Open(); cmd = new SqlCommand(QryStr, con); dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { txtEmpName.Text = dr["empname"].ToString(); txtEmpAdd.Text = dr["empaddress"].ToString(); txtEmpSal.Text = dr["empsalary"].ToString(); } else { txtEmpName.Focus(); } con.Close();
Deleting Records
QryStr = "DELETE FROM employeeinfo WHERE empid = '" + txtEmpId.Text + "'"; con.Open(); cmd = new SqlCommand(QryStr, con); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); con.Close();
Popularity: 2% [?]

December 3rd, 2008

admin
1.Using the label element allows the user to click on the text associated with the form control instead of having to click the radio button, check box, select box, etc.
2.To associate a label with another control implicitly, the control element must be within the contents of the Label element. In this case, the Label may only contain one control element. The label itself may be positioned before or after the associated control.
Example:-
<html>
<body>
// For Radio Button
<label for=”radio1″>Radio Button – Click this Label</label>
<input type=”radio” value=”Selected” name=”Radio” id=”radio1″>
// For CheckBox
<label for=”check”>Checkbox – Click this Label</label>
<input type=”checkbox” value=”Selected” name=”check” id=”check”>
</body>
</html>
Demo Link
Popularity: 8% [?]

December 3rd, 2008

admin
By default for controls placed in the designer the layout position is as ‘Not Set’ thus we cannot drag the control to a specified location.

We have to change the layout position to absolute position to achieve that.
In Visual Studio we can make the default postion as we need.For that we have to enable the css postioning of controls.
Here is how we can do
1. Go to Layout->Position->Auto-position Options->HTML Designer–>CSS Styling
or
2. Go to Tools->Options->HTML Designer–>CSS Positioning
And check “Change positioning to the following for controls added using Toolbox, paste or drag and drop” and select the postion you perfer.Here we select Absolute Positioning.
Now we can move the controls placed in the designer with absolute positioning.
The Given Procedure is for Visual Studio 2005 which is same for Visual Studio 2008.
Popularity: 17% [?]

December 2nd, 2008

admin
1.you can now add aggregate functions to any SELECT (even without a GROUP BY clause) by specifying an OVER() partition for each function.
2.SUM(..) OVER(..) is most useful for calculating a Total or percentage of a total for each row
3.SUM() function works with any of the other aggregate functions as well, such as MIN() or AVG()
- Partition by
-
Divides the result set into partitions. The window function is applied to each partition separately and computation restarts for each partition.
select
StudentId,
StudentName,
Subject,
Mark,
sum(Mark) OVER (Partition by StudentId) as Total
from
Student
Output
=====
StudentId StudentName Subject Mark Total
======= ========== ===== ==== =====
1 Raja Physics 80 240
1 Raja Maths 90 240
1 Raja Biology 70 240
2 Sam Physics 90 150
2 Sam Maths 60 150
Popularity: 4% [?]

December 1st, 2008

admin
Split Function: Delimiter :-
The space character ” ” we mentioned will be our delimiter and it is used by the split function as a way of breaking up the string. Every time it sees the delimiter we specified, it will create a new element in an array. The first argument of the split function is the delimiter.
Split() Function:-
The split() function splits text and puts the pieces into an array, with each piece taking up one slot in the array. For example, if you were to split “This is some text”,the split() function would create an array with four slots (zero to 3). The first slot in the array would contain “This”, the second slot would contain “is”, the third “some” and the fourth “text”.
Example:-
var stringdata= "1$2$3$4";
var splitdata = stringdata.split("$");
for(i = 0; i < splitdata.length; i++)
{
document.write("Element " + i + " = " + splitdata [i]);
}
Output
=====
Element 0 = 1
Element 1 = 2
Element 2 = 3
Element 3 = 4
Popularity: 3% [?]

December 1st, 2008

admin
1.create a date object and store it in a variable
2.Using the date object,Get the hour,minute,second,month,dayofmonth and year of the Current Date
var hour = d.getHours();
var minute = d.getMinutes();
var second = d.getSeconds();
var month = d.getMonth();
var dayofmonth = d.getDate();
var year = d.getYear();
Example:-
Display Next Day of Today
function getNextDate()
{
var date= new Date();
var day = date.getDate();
var month = date.getMonth();
var year = date.getYear();
var nextdate= new Date(year, month, day +1);
var nxtDate=nextdate.getMonth()+1+"/"+nextdate.getDate()+"/"+NextDate.getYear();
document.getElementById('DisplaynextDate').value=nxtDate;
//Display Next Date(today+1)
}
Popularity: 1% [?]