Showing posts with label Programming Tips. Show all posts
Showing posts with label Programming Tips. Show all posts

Transfering Data to Excel in C#  

The technique that is most frequently used to transfer data to an Excel workbook is Automation. With Automation, you can call methods and properties that are specific to Excel tasks. Automation gives you the greatest flexibility for specifying the location of your data in the workbook, formatting the workbook, and making various settings at run-time.

With Automation, you can use several techniques to transfer your data:

Transfer data cell by cell.
Transfer data in an array to a range of cells.
Transfer data in an ADO recordset to a range of cells by using the CopyFromRecordset method.
Create a QueryTable object on an Excel worksheet that contains the result of a query on an ODBC or OLEDB data source.
Transfer data to the clipboard, and then paste the clipboard contents into an Excel worksheet.
You can also use several methods that do not necessarily require Automation to transfer data to Excel. If you are running a server-side program, this can be a good approach for taking the bulk of data processing away from your clients.

To transfer your data without Automation, you can use the following approaches:
Transfer your data to a tab-delimited or comma-delimited text file that Excel can later parse into cells on a worksheet.
Transfer your data to a worksheet by using ADO.NET.
Transfer XML data to Excel (version 2002 and 2003) to provide data that is formatted and arranged into rows and columns.

Read More...

How to randomly selecting rows in SQL?  

If you need to randomly select one or more rows from one of your tables, then you can use the following query.

As an example we want to show an employee, randomly selected from the EMP table:

SELECT *
FROM (SELECT empno, ename
FROM emp
WHERE ename like '%'
ORDER BY DBMS_RANDOM.VALUE)
WHERE rownum <= 1;

EMPNO ENAME
---------- ----------
7566 JONES

If you need two employees, use:

SELECT *
FROM (SELECT empno, ename
FROM emp
WHERE ename like '%'
ORDER BY DBMS_RANDOM.VALUE)
WHERE rownum <= 2;

EMPNO ENAME
---------- ----------
7499 ALLEN
7844 TURNER

Read More...