Wednesday, May 20, 2009

SqlQuery To Export Data from Excel to Sql

Hi,
Here is the query to export the data from Excel to sqlserver

CREATE TABLE [dbo].[Addresses_Temp] (
[FirstName] VARCHAR(20),
[LastName] VARCHAR(20),
[Address] VARCHAR(50),
[City] VARCHAR(30),
[State] VARCHAR(2),
[ZIP] VARCHAR(10)
)
GO

INSERT INTO [dbo].[Address_Temp] ( [FirstName], [LastName], [Address], [City], [State], [ZIP] )
SELECT [FirstName], [LastName], [Address], [City], [State], [ZIP]
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Source\Addresses.xls;IMEX=1',
'SELECT * FROM [Sheet1$]')

To Access the function such as OPENROWSET Go to
MicroSoftSqlServer2005--->ConfigurationTools--->
SqlSurfaceAreaConfiguration

Click on Surface Area Configuration For features
and Enable OPENROWSET and OPENDATASOURCE support

Sunday, May 10, 2009

WildCharacters in Sql

Hi,
Here are the query results using Wild card Character.Consider below table
Student:

Now Consider the Query

Select * from student Where Name like ‘John%’.

It return results as name starts with john . You will get the result as



Select * from student Where Name like ‘%John’. It results as



Select * from student Where Name like ‘%John%’. It results as



Select * from student Where Class like ‘Fo_r’. '_' matches single character and replace it


Friday, May 8, 2009

What is a flat file?

A flat file is the name given to text, which can be read or written only sequentially.

Calculate Age from the DateOfBirth

Hi,
Here is the program with the three line to calculate the age from the DOB

long yrs = 0;
DateTime bdayDate = new DateTime(2010, 07, 17);
TimeSpan ts = DateTime.Now.Subtract(bdayDate);
yrs = ts.Days / 365;
Response.Write(yrs);

Saturday, April 25, 2009

Difference Between .net FrameWork 1.1,2.0,3.0,3.5

2.0 has some extendable features when compared to 1.1

1).net 2.0 supports web Request, web Response and web client classes

2).net 2.0 added the features of generic classes
3).net 2.0 added the feature of MultipleActiveResultSet,UserDefinedDataTypes,xmlDataTypes
4).net 2.0 UTF8Encoding is more faster than 1.1
5)When the file attachment u s

To read more Detail click the following link
http://msdn.microsoft.com/en-us/library/t357fb32.aspx

Difference between 2.0 and 3.0 is
WCF,WPF,WWF,WindowsCardSpace

3.0 and 3.5 is similar, with the additional features of enhanced WCF Control,ASp.net with Ajax , LinQ

Monday, February 2, 2009

Unsafe code may only appear if compiling with /unsafe in VisualStudio 2005

Hi,
Here is the error which i got when using unsafe code
Unsafe code may only appear if compiling with /unsafe
Here is the solution for the above error
Add the following line under system.codedom /compilers
compiler language="C#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" compilerOptions="/unsafe" /

UnSafe Code in C#

Hi,
Here is some details about Unsafe in C#
Unsafe code is code which does not executed under full control of CLR. It can cause some problems therefore each use must be marked as "unsafe".
...
unsafe
{
...
// unsafe context: can use pointers here
...
}
...
Generally speaking when you write any program in C# you create managed code. Managed code is executed under the control of Common Language Runtime (CLR). CRL causes that programmer do not need to manage memory and take care about memory's allocation and deallocation. CLR also allows you to write what is called 'unsafe code'.

Advantages:

  • Performance and flexibility, by using pointer you can access data and manipulate it in the most efficient way possible.
  • Compatibility, in most cases we still need to use old windows APIs, which use pointers extensively. Or third parties may supply DLLs that some of it’s functions need pointer parameters. Although this can be done by using DLLImport and System.IntPtr class, but in some cases it’s just much simpler to use pointer.
  • Memory Addresses, there is no way to know the memory address of some data without using pointers.

Disadvantages:

  • Complex syntax, to use pointers you need to go throw more complex syntax than we used to experience in C#.
  • Harder to use, you need be more careful and logical while using pointers, miss using pointer might lead to the following:
    • Overwrite other variables.
    • Stack overflow.
    • Access areas of memory that doesn’t contain any data as they do.
    • Overwrite some information of the code for the .net runtime, which will surely lead you application to crash.
  • Type-safety, using pointers will cause the code to fail in the .net type-safety checks, and of course if your Security policy don’t allow non type-safety code, then the .net framework will refuse to execute it.