Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Wednesday, April 28, 2010

Transaction in sqlserver

begin tran
begin try
insert into a(id) values('a')
insert into a1 values('sdf','adsf1212121',10012121)
commit tran
print'commit'
end try
begin catch
print'rollback'
rollback tran
end catch

Monday, April 26, 2010

Static Classes

A class can be declared static, indicating that it contains only static members. It is not possible to create instances of a static class using the new keyword. Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.

Use a static class to contain methods that are not associated with a particular object. For example, it is a common requirement to create a set of methods that do not act on instance data and are not associated to a specific object in your code. You could use a static class to hold those methods.

The main features of a static class are:

They only contain static members.

They cannot be instantiated.

They are sealed.

They cannot contain Instance Constructors (C# Programming Guide).

Creating a static class is therefore much the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated.

The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created.

Static classes are sealed and therefore cannot be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.

STUFF vs REPLACE in Asp.net

STUFF - Deletes a specified length of characters and inserts another set of characters at a specified starting point.
SELECT STUFF('abcdef', 2, 3, 'ijklmn')
GO
Here is the result set:
---------
aijklmnef
REPLACE - Replaces all occurrences of the second given string expression in the first string expression with a third expression.
SELECT REPLACE('abcdefghicde','cde','xxx')
GO
Here is the result set:
------------
abxxxfghixxx

DDL, DML, DCL and TCL Commands

DML

DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.

SELECT – Retrieves data from a table
INSERT - Inserts data into a table
UPDATE – Updates existing data into a table
DELETE – Deletes all records from a table

DDL

DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database.

CREATE – Creates objects in the database
ALTER – Alters objects of the database
DROP – Deletes objects of the database
TRUNCATE – Deletes all records from a table and resets table identity to initial value.

DCL

DCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.

GRANT – Gives user’s access privileges to database
REVOKE – Withdraws user’s access privileges to database given with the GRANT command

TCL

TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring within a database.

COMMIT – Saves work done in transactions
ROLLBACK – Restores database to original state since the last COMMIT command in transactions
SAVE TRANSACTION – Sets a savepoint within a transaction

Saturday, April 24, 2010

Get Vs Post Method

Get Vs Post Method to send data to the server

Get and Post are methods used to send data to the server:
With the Get method, the browser appends the data onto
the URL. With the Post method, the data is sent
as "standard input."

Use GET:
- during development for debugging purposes (although in ASP.NET it's
also easy to see what has been sent through POST).
- if you want your visitors to be able to bookmark the submitted pages
- if you want to refer to submitted pages using hyperlinks

Use POST:
- for forms with password fields
- for large forms or forms with large text fields

Please note that web forms in ASP.NET use POST by default.

It can be changed into GET, but only for small forms. Web forms can post a lot
of data, especially when ViewState is involved.

Monday, April 19, 2010

Jquery Events

Events Jquery

.bind()
Event Handler Attachment
Attach a handler to an event for the elements.
.blur()
Form Events, Forms
Bind an event handler to the "blur" JavaScript event, or trigger that event on an element.
.change()
Form Events, Forms
Bind an event handler to the "change" JavaScript event, or trigger that event on an element.
.click()
Mouse Events
Bind an event handler to the "click" JavaScript event, or trigger that event on an element.
.dblclick()
Mouse Events
Bind an event handler to the "dblclick" JavaScript event, or trigger that event on an element.
.delegate()
Event Handler Attachment
Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.
.die()
Event Handler Attachment
Remove all event handlers previously attached using .live() from the elements.
.error()
Browser Events
Bind an event handler to the "error" JavaScript event.
event.currentTarget
Event Object
The current DOM element within the event bubbling phase.
event.data
Event Object
Contains the optional data passed to jQuery.fn.bind when the current executing handler was bound.
event.isDefaultPrevented()
Event Object
Returns whether event.preventDefault() was ever called on this event object.
event.isImmediatePropagationStopped()
Event Object
Returns whether event.stopImmediatePropagation() was ever called on this event object.
event.isPropagationStopped()
Event Object
Returns whether event.stopPropagation() was ever called on this event object.
event.pageX
Event Object
The mouse position relative to the left edge of the document.
event.pageY
Event Object
The mouse position relative to the top edge of the document.
event.preventDefault()
Event Object
If this method is called, the default action of the event will not be triggered.
event.relatedTarget
Event Object
The other DOM element involved in the event, if any.
event.result
Event Object
This attribute contains the last value returned by an event handler that was triggered by this event, unless the value was undefined.
event.stopImmediatePropagation()
Event Object
Prevents other event handlers from being called.
event.stopPropagation()
Event Object
Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
event.target
Event Object
The DOM element that initiated the event.
event.timeStamp
Event Object
This attribute returns the number of milliseconds since January 1, 1970, when the event is triggered.
event.type
Event Object
Describes the nature of the event.
event.which
Event Object
For key or button events, this attribute indicates the specific button or key that was pressed.
.focus()
Form Events, Forms
Bind an event handler to the "focus" JavaScript event, or trigger that event on an element.
.focusin()
Keyboard Events, Mouse Events
Bind an event handler to the "focusin" JavaScript event.
.focusout()
Keyboard Events, Mouse Events
Bind an event handler to the "focusout" JavaScript event.
.hover()
Mouse Events
Bind two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.
.keydown()
Keyboard Events
Bind an event handler to the "keydown" JavaScript event, or trigger that event on an element.
.keypress()
Keyboard Events
Bind an event handler to the "keypress" JavaScript event, or trigger that event on an element.
.keyup()
Keyboard Events
Bind an event handler to the "keyup" JavaScript event, or trigger that event on an element.
.live()
Event Handler Attachment
Attach a handler to the event for all elements which match the current selector, now or in the future.
.load()
Document Loading
Bind an event handler to the "load" JavaScript event.
.mousedown()
Mouse Events
Bind an event handler to the "mousedown" JavaScript event, or trigger that event on an element.
.mouseenter()
Mouse Events
Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element.
.mouseleave()
Mouse Events
Bind an event handler to be fired when the mouse leaves an element, or trigger that handler on an element.
.mousemove()
Mouse Events
Bind an event handler to the "mousemove" JavaScript event, or trigger that event on an element.
.mouseout()
Mouse Events
Bind an event handler to the "mouseout" JavaScript event, or trigger that event on an element.
.mouseover()
Mouse Events
Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element.
.mouseup()
Mouse Events
Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element.
.one()
Event Handler Attachment
Attach a handler to an event for the elements. The handler is executed at most once per element.
jQuery.proxy()
Event Handler Attachment, Utilities
Takes a function and returns a new one that will always have a particular context.
.ready()
Document Loading
Specify a function to execute when the DOM is fully loaded.
.resize()
Browser Events
Bind an event handler to the "resize" JavaScript event, or trigger that event on an element.
.scroll()
Browser Events
Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element.
.select()
Form Events, Forms
Bind an event handler to the "select" JavaScript event, or trigger that event on an element.
.submit()
Form Events, Forms
Bind an event handler to the "submit" JavaScript event, or trigger that event on an element.
.toggle()
Basics, Mouse Events
Bind two or more handlers to the matched elements, to be executed on alternate clicks.
.trigger()
Event Handler Attachment
Execute all handlers and behaviors attached to the matched elements for the given event type.
.triggerHandler()
Event Handler Attachment
Execute all handlers attached to an element for an event.
.unbind()
Event Handler Attachment
Remove a previously-attached event handler from the elements.
.undelegate()
Event Handler Attachment
Remove a handler from the event for all elements which match the current selector, now or in the future, based upon a specific set of root elements.
.unload()
Document Loading
Bind an event handler to the "unload" JavaScript e

What is the difference between JavaScript and jQuery?

What is the difference between JavaScript and jQuery?

JavaScript is a language whereas jQuery is a library written using JavaScript.

What does dollar Sign ($) means in JQuery?

Dollar Sign is nothing but it's an alias for JQuery.

Over here $ sign can be replaced with jQuery...

LINQ :: Language Integrated Query

you can find several descriptions of Language Integrated Query (LINQ), such as these:

LINQ is a uniform programming model for any kind of data. LINQ enables you to query and manipulate data with a consistent model that is independent from data sources.

LINQ is just another tool for embedding SQL queries into code.

LINQ is yet another data abstraction layer.

All of these descriptions are somewhat correct, but they each focus on just a single aspect. LINQ can do a lot more than just embed SQL queries, it is much easier to use than a “uniform programming model,” and it is far from being just another set of rules for modeling data.

LINQ is a methodology that simplifies and unifies the implementation of any kind of data access. LINQ does not force you to use a specific architecture; it facilitates the implementation of several existing architectures for accessing data. As with every tool, it can be used in both good and in bad ways. To get the most out of LINQ, you will have to master it.

Today, data managed by a program can belong to different data domains: an array, an object graph, an XML document, a database, a text file, a registry key, an e-mail message, Simple Object Access Protocol (SOAP) message content, a Microsoft Office Excel file…. The list is long.

Each data domain has its own specific access model. When you have to query a database, you typically use SQL. You navigate XML data with Document Object Model (DOM) or XQuery. You iterate an array and build algorithms to navigate an object graph. You use specific application programming interfaces (APIs) to access other data domains, such as an Office Excel file, an e-mail message, or the Microsoft Windows registry. In the end, you have different programming models to access different data sources.

The unification of data access techniques into a single comprehensive model has been tried in many ways. For example, there are Open Database Connectivity (ODBC) providers that allow you to query an Excel file as you would a Windows Management Instrumentation (WMI) repository. However, with this approach you use an SQL-like language to access data represented through a relational model. Sometimes data is naturally represented more effectively in a hierarchical or graphical model instead of a relational one. Moreover, if the data model is not tied to the language, you probably have to manage different type systems. All these differences create an “impedance mismatch” between data and code. LINQ tries to solve these issues, offering a uniform way to access and manage data without forcing the adoption of a “one size fits all” model. LINQ leverages commonalities between the operations in these data models instead of flattening the different structures between them.

Tuesday, April 13, 2010

Validate TextBox

//Take one text box and call the function obblur method........

asp:TextBox ID="txt" runat="server" onblur="ValidateCCNum(this);">

//.js File
function ValidateCCNum(ccNum)
{
var ccno = ccNum.value;
if(ccno == "")
{

return true;
}

if(isNaN(ccno))
{

alert("Credit card number should be numeric");
ccNum.value="";
ccNum.focus();

return false;
}
if(ccno.length < 14 || ccno.length >18)
{

alert("Credit card number should have 14-18 digits length");
ccNum.value="";
ccNum.focus();

return false;
}
return true;
}

Monday, April 12, 2010

Deleted Trigger

//titleauthor is foreigntable
//titles Primary Table......When you delete data from Primary automatically delete data from foreign table.....
//title_id is a Unique key in both table..
//deleted is a magic Table where delete data is stored...

create trigger delcascadetrig
on titleauthor
for delete
as
delete delcascadetrig
from titles, deleted
where titles.title_id = deleted.title_id

Saturday, April 3, 2010

Bind GridView with Datatable

Add a GridView control, two lable controls, three textbox controls and button control in the page
Create datatable structure.

private DataTable CreateDataTable()
{
DataTable myDataTable = new DataTable();
DataColumn myDataColumn;
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "id";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "username";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "firstname";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "lastname";
myDataTable.Columns.Add(myDataColumn);
return myDataTable;
}


Insert data into datatable.

private void AddDataToTable(string username,string firstname,string lastname,DataTable myTable)
{
DataRow row;
row = myTable.NewRow();
row["id"] = Guid.NewGuid().ToString();
row["username"] = username;
row["firstname"] = firstname;
row["lastname"] = lastname;
myTable.Rows.Add(row);
}


//Add data to datatable which we have created

protected void btnAdd_Click(object sender, EventArgs e)
{
if (txtUserName.Text.Trim() == "")
{
this.lblTips.Text = "You must fill a username.";
return;
}
else
{
AddDataToTable(parameter);
this.txtFirstName.Text = "";
this.txtLastName.Text = "";
this.txtUserName.Text = "";
this.lblTips.Text = "";
}
}

// Page Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable myDt = new DataTable();
myDt = CreateDataTable();
this.GridView1.DataSource = myDt
this.GridView1.DataBind();
}
}