Monday, May 31, 2010

Make connection with .dbf file and read and write with C# .

There are two way to make connection with .dbf file :

1. With ODBC Connection.

           string filepath = "c:\\nn\\";
           
           OdbcConnection CC = new OdbcConnection("Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=" + filepath + ";Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;");
            CC.Open();
           
            OdbcCommand cmd = new OdbcCommand("Select * From " + filepath + "smsout.dbf" , CC);
            OdbcDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                DataTable dt = new DataTable();
                dt.Load(dr);
            }
            CC.Close();

2. With OLEDB Connection.

            OleDbConnection ccc = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath.Substring(0, filepath.LastIndexOf("\\")) + ";Extended Properties=dBASE IV;");
            ccc.Open();
            OleDbCommand cmd1 = new OleDbCommand("Select * From " + filepath + "smsout.dbf", ccc);
            OleDbDataReader dr1 = cmd1.ExecuteReader();
            if (dr1.HasRows)
            {
                DataTable dt1 = new DataTable();
                dt1.Load(dr1);
            }
            ccc.Close();

Wednesday, May 19, 2010

What is Decode sql functions ?

Decode is the sql functions for the replacement of If- Then -else logic and case is similar to
If-Then-else logic except that we can make logical comparison of columns involved in the case
structures.
Ex: select case snum when snum > 10 then 'High' when snum>5 then 'Low' end from sales.

Ex: select decode(snum,10,'high',5,'low') from sales... that is we cannot make logical comparison of columns in Decode() functions.

Ex: SELECT NAME,SAL,DECODE(DEPTNO,10,'ACCOUNTING',20,'RESEARCH',30,'SALES',40,'OPERATIONS','OTHERS')
"DEPARTMENTS" FROM EMP;

A DECODE FUNCTION ALWAYS TAKES MINIMUM OF 4 ARGUMENTS
DECODE
IF N1=N2
THEN RETURN N3
ELSE
RETURN N4

Diffrence between SCOPE_IDENTITY, IDENT_CURRENT, and @@IDENTITY

SCOPE_IDENTITY, IDENT_CURRENT, and @@IDENTITY are similar functions in that they return values inserted into IDENTITY columns.

IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the value generated for a specific table in any session and any scope.

SCOPE_IDENTITY and @@IDENTITY will return last identity values generated in any table in the current session. However, SCOPE_IDENTITY returns values inserted only within the current scope; @@IDENTITY is not limited to a specific scope.

For example, you have two tables, T1 and T2, and an INSERT trigger defined on T1. When a row is inserted to T1, the trigger fires and inserts a row in T2. This scenario illustrates two scopes: the insert on T1, and the insert on T2 as a result of the trigger.

Assuming that both T1 and T2 have IDENTITY columns, @@IDENTITY and SCOPE_IDENTITY will return different values at the end of an INSERT statement on T1.
@@IDENTITY will return the last IDENTITY column value inserted across any scope in the current session, which is the value inserted in T2.
SCOPE_IDENTITY() will return the IDENTITY value inserted in T1, which was the last INSERT that occurred in the same scope. The SCOPE_IDENTITY() function will return the NULL value if the function is invoked before any insert statements into an identity column occur in the scope.

What is the difference between #include and #include ?file?? or "file"

We have two ways to include files in a project.

The first way is to include with the angled brackets <>. This method of inclusion tells the compiler to look for the file in the predefined default location. This predefined default location is often an INCLUDE environment variable that denotes the path to your include files. For instance, given the INCLUDE variable
INCLUDE=C:COMPILERINCLUDE;S:SOURCEHEADERS;

If the file is not found there, the compiler then checks the S:SOURCEHEADERS directory. If the file is still not found, the compiler checks the current directory.

The second way to include files is include with double quotation marks. This method of inclusion tells the compiler to look for the file in the current directory first, then look for it in the predefined locations you have set up. Using the #include ?file? version of file inclusion and applying it to the preceding example, the compiler first checks the current directory for the
specified file. If the file is not found in the current directory, the C:COMPILERINCLUDE directory is searched. If the file is still not found, the compiler checks the S:SOURCEHEADERS directory.

The #include method of file inclusion is often used to include standard headers such as stdio.h or stdlib.h. This is because these headers are rarely (if ever) modified, and they should always be read from your compiler?s standard include file directory.

The #include ?file? method of file inclusion is often used to include nonstandard header files that you have created for use in your program. This is because these headers are often modified in the current directory, and you will want the compiler to use your newly modified version of the header rather than the older, unmodified version.

#include
This will refer the given file in the standard input and output directory.
but
#include"file"
This will first refers the given file in the current directory if this not found it will refers in the standard input and output directory.

Tuesday, May 4, 2010

Three way to get the name of month from a Date.

1. string str= String.Format("{0:mmmm}", DateTime.Now);

2. string str = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Month);

3. System.Globalization.DateTimeFormatInfo ifo = new
System.Globalization.DateTimeFormatInfo();
str = ifo.GetMonthName(Date.Month);

By following the same way you can also get the name of the year or day of from date.

Thanks.

Thursday, April 29, 2010

Diffrence Between MFC and ATL projects

Microsoft Foundation Classes (MFC)
The C++ class library that Microsoft provides with its C++ compiler to assist programmers in creating Windows-based applications. MFC hides the fundamental Windows API in class hierarchies so that programmers can write a Windows-based application without needing to know the details of the native Windows API.
Microsoft created MFC to make the development of applications for Windows much easier than it was using the SDK.

Active Template Library (ATL)
A C++ template library used to create ActiveX servers and other Component Object Model (COM) objects. ActiveX controls created with ATL are generally smaller and faster than those created with the Microsoft Foundation Classes.
ATL provides a framework to implement the code necessary to create
COM clients and servers. The two frameworks overlap in their usefulness for
developing ActiveX controls.
ATL's purpose in is to save developers from having to rewrite IUnknown,
IDispatch, IClassFactory, and all the hooks for turning regular DLLs and EXEs into
COM-based DLLs and EXEs. In this respect, ATL is a much lighter framework than MFC,
and ATL was designed and built with COM support in mind.

The differences between the two architectures are fairly stark. Generally, MFC enables you to get your project up and running more quickly, but sacrifices flexibility. ATL isn't quite as quick and easy to use, but it is COM-friendly. In addition, ATL appears to be getting easier to use as it matures.

Thanks.

About Active X and COM

ActiveX
A set of technologies that enable software components to interact with one another in a networked environment, regardless of the language in which the components were created. ActiveX, which was developed as a proposed standard by Microsoft in the mid 1990s and is currently administered by the Open Group, is built on Microsoft's Component Object Model (COM). Currently, ActiveX is used primarily to develop interactive content for the World Wide Web, although it can be used in desktop applications and other applications. ActiveX controls can be embedded in Web pages to produce animation and other multimedia effects, interactive objects, and sophisticated applications. See also COM.

ActiveX client
An application or tool that calls an ActiveX object.

ActiveX object
An exposed object of the Component Object Model (COM).

Component Object Model (COM)
An open architecture for cross-platform development of client/server applications. It is based on object-oriented technology as agreed upon by Digital Equipment Corporation and Microsoft Corporation. COM defines the interface, similar to an abstract base class, IUnknown, from which all COM-compatible classes are derived.

Thanks.