try
{
SqlConnection objConnection =
objConnection.ConnectionString = "Server=(local);Database=MyDatabase;uid=myid;pwd=mypassword;Connect Timeout=300";
objConnection.Open();
SqlCommand thisCommand = objConnection.CreateCommand();
" billingitem, amount, " +
" lastname + ', ' + firstname + ' ' + middlename as employee, " +
" ep.startdate as emp_startdate, ep.enddate as emp_enddate "+
" from invoice i " +
" inner join invoicedetail ind on i.invoiceid = ind.invoiceid " +
" inner join billingitem b on ind.billingitemid = b.billingitemid " +
" inner join EmployeeInvoiceDetail eid on ind.invoicedetailid = eid.invoicedetailid " +
" inner join project p on i.projectid = p.projectid " +
" inner join employee e on eid.employeeid = e.employeeid " +
" inner join employeeproject ep on e.employeeid = ep.employeeid and p.projectid = ep.projectid " +
" where i.startdate between '01/1/2005' and '12/31/2005' and i.enddate between '01/1/2005' and '12/31/2005' and i.projectid='10'";
thisCommand.CommandText = query;
SqlDataReader thisReader = thisCommand.ExecuteReader();
Excel.Application ExcelObj =
ExcelObj =
ExcelObj.Visible =
Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(
@"C:\Excel_Pivot.xls", 0,
"", "",
0,
Excel.Sheets sheet = theWorkbook.Worksheets;
Excel.Worksheet worksheet = (Excel.Worksheet)sheet.get_Item(2);
ctr++;
Range invoiceid = (Range)worksheet.Cells[ctr,"A"];
invoiceid.Value2 = thisReader["invoiceid"];
Range invoiceno = (Range)worksheet.Cells[ctr,"B"];
invoiceno.Value2 = thisReader["invoiceno"];
Range projectname = (Range)worksheet.Cells[ctr,"C"];
projectname.Value2 = thisReader["projectname"];
Range startdate = (Range)worksheet.Cells[ctr,"D"];
startdate.Value2 = thisReader["startdate"];
Range enddate = (Range)worksheet.Cells[ctr,"E"];
enddate.Value2 = thisReader["enddate"];
Range billingitem = (Range)worksheet.Cells[ctr,"F"];
billingitem.Value2 = thisReader["billingitem"];
Range amount = (Range)worksheet.Cells[ctr,"G"];
amount.Value2 = thisReader["amount"];
Range employee = (Range)worksheet.Cells[ctr,"H"];
employee.Value2 = thisReader["employee"];
Range emp_startdate = (Range)worksheet.Cells[ctr,"I"];
emp_startdate.Value2 = thisReader["emp_startdate"];
Range emp_enddate = (Range)worksheet.Cells[ctr,"J"];
emp_enddate.Value2 = thisReader["emp_enddate"];
}
thisReader.Close();
objConnection.Close();
x = ex.Message;
}------------------------------------I really need this working, please help. Thanks! ^_^