Friday, October 26, 2012

Insert Record(s) to a Table from Another Table



insert into TableDocument2(DocumentId, DeptId, a, b, c, d,e) 
select DocumentId, 9, f, g, h, i, NULL from TableDocument


Wednesday, October 24, 2012

Get the Sum of a Particular DataTable Column

Use the DataTable.Compute method


    DataTable table;
table = dataSet.Tables["Orders"];

// Declare an object variable. 
object sumObject;
sumObject = table.Compute("Sum(Total)", "EmpID = 5");
where "EmpID = 5" is a filter expression. 

Use empty string if filter expression is not needed.

Tuesday, October 23, 2012

Get "2 days before" Dates


Get "2 days before" dates
SELECT * FROM Table1 WHERE DATEDIFF(day, CURRENT_TIMESTAMP, SampleDateField) = 2; 

Another sample usage of DATEDIFF
SELECT DATEDIFF(day, CURRENT_TIMESTAMP, SampleDateField) as 'Days' from Table1

Wednesday, October 10, 2012

Convert PagedCollectionView to Original Source

ObservableCollection<SavedReport> obvColSavedReports = new ObservableCollection<SavedReport>();
                foreach (var savedReport in ((PagedCollectionView)dataGrid1.ItemsSource).SourceCollection)
                {
                    SavedReport sr = (SavedReport)savedReport;
                    if (sr.IsSelected)
                        obvColSavedReports.Add(sr);
                }


See the bold text above? That's it!

Tuesday, October 2, 2012

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.



Problem Summary:
I am getting the above error when I'm trying to import data from excel file in the production server. But, import excel is working on my local machine.

Cause:
The server does not have the proper DLL installed.

Solution:
Install the Office System Driver: Data Connectivity Components in the server.