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.