Tuesday, August 30, 2011

Renaming a table or storedprocedure or a column

Rename any object in sql server 2005

if u want to rename any object with command then you have to use in-built system stored procedure which is sp_rename

for renaming the column of a table you have to write the following statement


sp_RENAME 'dbo.tablename.oldname', 'NameChange' , 'COLUMN'


but for the storedprocedure and table you dont have to mention the third parameter



sp_rename 'old_table_name', 'new_table_name'



From MSDN
--------------------------



You can change the name of an object or data type in the current database only. The names of most system data types and system objects cannot be changed.

When you rename a view, information about the view is updated in the sysobjects table. When you rename a stored procedure, information about the procedure is changed in the sysobjects table.

sp_rename automatically renames the associated index whenever a PRIMARY KEY or UNIQUE constraint is renamed. If a renamed index is tied to a PRIMARY KEY constraint, the primary key is also automatically renamed by sp_rename.

Important After renaming stored procedures and views, flush the procedure cache to ensure all dependent stored procedures and views are recompiled.

Renaming a stored procedure, view or trigger will not change the name of the corresponding object name in the syscomments table. This may result in problems generating a script for the object as the old name will be inserted from the syscomments table into the CREATE statement. For best results, do not rename these object types. Instead, drop and re-create the object by its new name.

Wednesday, August 17, 2011

Classes and structs

From MSDN
Classes and structs are two of the basic constructs of the common type system in the .NET Framework. Each is essentially a data structure that encapsulates a set of data and behaviors that belong together as a logical unit. The data and behaviors are the members of the class or struct, and they include its methods, properties, and events, and so on, as listed later in this topic.

A class or struct declaration is like a blueprint that is used to create instances or objects at run time. If you define a class or struct called Person, Person is the name of the type. If you declare and initialize a variable p of type Person, p is said to be an object or instance of Person. Multiple instances of the same Person type can be created, and each instance can have different values in its properties and fields.

A class is a reference type. When an object of the class is created, the variable to which the object is assigned holds only a reference to that memory. When the object reference is assigned to a new variable, the new variable refers to the original object. Changes made through one variable are reflected in the other variable because they both refer to the same data.

A struct is a value type. When a struct is created, the variable to which the struct is assigned holds the struct's actual data. When the struct is assigned to a new variable, it is copied. The new variable and the original variable therefore contain two separate copies of the same data. Changes made to one copy do not affect the other copy.

In general, classes are used to model more complex behavior, or data that is intended to be modified after a class object is created. Structs are best suited for small data structures that contain primarily data that is not intended to be modified after the struct is created.

Difference between Struct and Class
Struct are Value type and are stored on stack, while Class are Reference type and are stored on heap.

Struct “do not support” inheritance, while class supports inheritance. However struct can implements interface.

Struct should be used when you want to use a small data structure, while Class is better choice for complex data structure.



Choosing between struct and class

Use of structure in following condition is desirable.
  • When you have small data structure
  • Data Structure does not require to extent the functionality.
  • When you want to perform faster operation on data structure. (As structure are stored on stack, operation performed on it are faster.)

Use of class in following condition is desirable.
  • When you have complex data structure
  • Data Structure requires to extend functionality.
  • When you want to optimize memory usage. (As class is stored on heap, they are about to be garbage collected when no reference pointing to an object.)


What is the difference between instantiating structures with and without using the new keyword?

When a structure is instantiated using the new keyword, a constructor (no-argument or custom, if provided) is called which initializes the fields in the structure. When a structure is instantiated without using the new keyword, no constructor is called. Hence, one has to explicitly initialize all the fields of the structure before using it when instantiated without the new keyword.


FROM StackOverFlow.com
In .NET, there are two categories of types, reference types and value types.

Structs are value types and classes are reference types.

The general different is that a reference type lives on the heap, and a value type lives inline, that is, wherever it is your variable or field is defined.

A variable containing a value type contains the entire value type value. For a struct, that means that the variable contains the entire struct, with all its fields.

A variable containing a reference type contains a pointer, or a reference to somewhere else in memory where the actual value resides.

This has one benefit, to begin with:
• value types always contains a value
• reference types can contain a null-reference, meaning that they don't refer to anything at all at the moment
Internally, reference types are implemented as pointers, and knowing that, and knowing how variable assignment works, there are other behavioral patterns:
• copying the contents of a value type variable into another variable, copies the entire contents into the new variable, making the two distinct. In other words, after the copy, changes to one won't affect the other
• copying the contents of a reference type variable into another variable, copies the reference, which means you now have two references to the same somewhere else storage of the actual data. In other words, after the copy, changing the data in one reference will appear to affect the other as well, but only because you're really just looking at the same data both places
When you declare variables or fields, here's how the two types differ:
• variable: value type lives on the stack, reference type lives on the stack as a pointer to somewhere in heap memory where the actual memory lives
• class/struct-field: value type lives inside the class, reference type lives inside the class as a pointer to somewhere in heap memory where the actual memory lives.


A short summary of each:
Classes Only:
• Can support inheritance
• Are reference types
• Have memory overhead per new instance
Structs Only:
• Cannot support inheritance
• Are value types
• Do not have a memory overhead per new instance - unless 'boxed'
Both Classes and Structs:
• Are compound data types typically used to contain a few variables that have some logical relationship
• Can contain methods and events
• Can support interfaces



Thursday, July 28, 2011

Why income tax return is so complicated in India?

Hi to everyone,
I am a computer professionalize and as far as I think I am well educated. Yester night I see a TV advertisement about its now easy to fill “e-return” in India and i am also thinking to fill the return this year so by inspired by that TV add , when I come to office open the google.in and type the e-filling tax , and it gives me the list link as expected from “ google guru”. I go through the first link which is an official website of our nation to fill the return http://www.incometaxindia.gov.in/home.asp and there is a lot of menus in the left hand side but I didn’t getting any idea on which link should I go. I am very much confused between the fourth and fifth menus which are File return online and Pay taxes online. Really I never thought it will have so much confusion and financial terms. As I working in a private company so this will be the reason else in government offices everyone know how to fill tax return and what they get if govt approve any extra TA DA or any allowance for them. They have so much time to calculate all these things but we don’t have.
Can it is not possible that there is a simple form which have some basic enquiry + pen card number +my bank statements and any other thing required then there is upload option and when I fill the form then email to me and my company and after confirmation from my company my income tax return is successfully submitted. As I go through my idea there can be lot more improvement or amendments can be done but it will be simple for us. Hoping that anybody have same trouble and it will change the pattern ……………………..

Sample app or project for the MVC ?

Looking from a long time to get the opportunity to work in MVC framework and I know the basic what is MVC and how it works? How it differs from the traditional web forms, but not getting any project in my companies and lot of other issues are regularly facing which keep myself busy so the main point is that missing the right time and right opportunity to clean my MVC hands.

In those days I am big fan of http://stackoverflow.com so there I got lot of knowledge today any user similar to me in MVC knowledge asked “What will be the right way to start a project on MVC” and the answer is http://nerddinner.com/ (NerdDinner 2.0 Complete ASP.NET MVC Sample App) and source code is also available on codeplex (Project Hosting for Open Source Software) http://nerddinner.codeplex.com/ so the objective of my blogging share my knowledge to my readers. So this is the answer of sample app or project for the MVC ?

Wednesday, July 27, 2011

date formats

Date and Time Format Patterns






All

the

patterns:
0MM/dd/yyyy07/27/2011
1

dddd, dd MMMM yyyy
Wednesday, 27 July 2011
2dddd, dd

MMMM yyyy HH:mm
Wednesday, 27 July 2011 08:40
3dddd, dd

MMMM yyyy hh:mm tt
Wednesday, 27 July 2011 08:40

AM
4dddd, dd MMMM yyyy H:mmWednesday, 27 July 2011

8:40
5dddd, dd MMMM yyyy h:mm ttWednesday, 27 July 2011

8:40 AM
6dddd, dd MMMM yyyy HH:mm:ssWednesday, 27 July

2011 08:40:28
7MM/dd/yyyy HH:mm07/27/2011

08:40
8MM/dd/yyyy hh:mm tt07/27/2011 08:40

AM
9MM/dd/yyyy H:mm07/27/2011

8:40
10MM/dd/yyyy h:mm tt07/27/2011 8:40

AM
11MM/dd/yyyy HH:mm:ss07/27/2011

08:40:28
12MMMM ddJuly 27
13MMMM

dd
July

27
14yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK2011-07-27T0

8:40:28.2891564-04:00
15yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK2011-07-27T08:40:28.2891564-04:00
16ddd, dd MMM yyyy

HH':'mm':'ss 'GMT'
Wed, 27 Jul 2011 08:40:28 GMT
17ddd,

dd MMM yyyy HH':'mm':'ss 'GMT'
Wed, 27 Jul 2011 08:40:28

GMT
18yyyy'-'MM'-'dd'T'HH':'mm':'ss2011-07-27T08:40:28< /td>
19HH:mm08:40
20hh:mm

tt
08:40

AM
21H:mm8:40
22h:mm

tt
8:40

AM
23HH:mm:ss08:40:28
24yyyy'-'MM

'-'dd HH':'mm':'ss'Z'
2011-07-27 08:40:28Z
25dddd, dd

MMMM yyyy HH:mm:ss
Wednesday, 27 July 2011

08:40:28
26yyyy MMMM2011

July
27yyyy MMMM2011 July

The patterns for

DateTime.ToString ( 'd' )

:
0MM/dd/yyyy07/27/2011

The patterns for

DateTime.ToString ( 'D' ) :
0dddd, dd MMMM

yyyy
Wednesday, 27 July 2011

The patterns for

DateTime.ToString ( 'f' ) :
0dddd, dd MMMM yyyy

HH:mm
Wednesday, 27 July 2011 08:40
1dddd, dd MMMM yyyy

hh:mm tt
Wednesday, 27 July 2011 08:40 AM
2dddd, dd MMMM

yyyy H:mm
Wednesday, 27 July 2011 8:40
3dddd, dd MMMM

yyyy h:mm tt
Wednesday, 27 July 2011 8:40 AM

The patterns for

DateTime.ToString ( 'F' ) :
0dddd, dd MMMM yyyy

HH:mm:ss
Wednesday, 27 July 2011 08:40:28

The patterns for

DateTime.ToString ( 'g' ) :
0MM/dd/yyyy HH:mm07/27/2011

08:40
1MM/dd/yyyy hh:mm tt07/27/2011 08:40

AM
2MM/dd/yyyy H:mm07/27/2011

8:40
3MM/dd/yyyy h:mm tt07/27/2011 8:40

AM

The patterns for DateTime.ToString ( 'G' )

:
0MM/dd/yyyy HH:mm:ss07/27/2011

08:40:28

The patterns for DateTime.ToString ( 'm' )

:
0MMMM ddJuly 27

The patterns for

DateTime.ToString ( 'r' ) :
0ddd, dd MMM yyyy HH':'mm':'ss

'GMT'
Wed, 27 Jul 2011 08:40:28 GMT

The patterns for

DateTime.ToString ( 's' )

:
0yyyy'-'MM'-'dd'T'HH':'mm':'ss2011-07-27T08:40:28

The patterns for DateTime.ToString ( 'u' )

:
0yyyy'-'MM'-'dd HH':'mm':'ss'Z'2011-07-27

08:40:28Z

The patterns for DateTime.ToString ( 'U' )

:
0dddd, dd MMMM yyyy HH:mm:ssWednesday, 27 July 2011

08:40:28

The patterns for DateTime.ToString ( 'y' )

:
0yyyy MMMM2011 July




download box instead of direct open file in new window.

#region download-file
static public void DownloadFile(string filePath)
{
try
{
filePath = filePath.Replace(" ", "_");
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(filePath));
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.WriteFile(filePath);
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion

Friday, July 8, 2011

How to insert complete dataset values into sql server 2005+ using XML

First we have to convert the ds into xml and pass it to the stored

procedure.
For the sake of simplicity i created here a xml schema @xml-schema and temporary table #TempTable.


DECLARE @ixml int
DECLARE @xml-schema varchar(max)
SET @xml-schema ='





'

--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @ixml OUTPUT, @xml-schema
-- Execute a SELECT statement that uses the OPENXML rowset provider.


SELECT *
Into #TempTable
FROM OPENXML(@ixml, '/ROOT/Trans',1)
WITH
(
TransId varchar(10),
[Add] bit,
Edit bit,
[Delete] bit,
[View] bit,
Block bit
)

Select * From #TempTable

drop table #TempTable




You can change it as per your requirement . have any query please contact me rahularyansharma@gmail.com

ASP.NET Core

 Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...