queryStr= "SELECT log.date,log.log_inquiry_id,inq.company,inq.inquiry_id,log.subject,log.medium,log.subject_type,log.comments,logg.name FROM crm_inquiry_log_details log "
+ "INNER JOIN crm_inquiry_perticipant inq ON inq.inquiry_id = log.inquiry_id"
+ " INNER JOIN crm_login logg ON inq.inquiry_owner=logg.log_id "
+ " WHERE "
+ "(( " + owner + "=0) OR (inq.inquiry_owner=" + owner + "))" +
// " (('" + StartDateString + "'='') OR (log.date BETWEEN '" + StartDateString + "' AND '" + EndDateString + "')) " +
"order by log_inquiry_id desc";
In the above query, i am selecting the date(log.date) so that after exporting, it(date column) should be shown in excel file. But,it is not showing. Rest all columns are showing. whats wrong with that?
protected void ExportToExcel(DataTable dt)
{
try
{
if (dt.Rows.Count > 0)
{
string filename = "Log Reports.xls";
string excelHeader = "Log Report";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.HeaderStyle.BackColor = Color.Pink;
dgGrid.DataSource = dt;
dgGrid.BorderStyle = BorderStyle.None;
dgGrid.DataBind();
hw.WriteLine("<b><u><font size=’3′> " + excelHeader + " </font></u></b>");
dgGrid.RenderControl(hw);
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
}
catch (Exception ex1)
{
}
}
protected void buttGraph_Click(object sender, EventArgs e)//export
{
try
{
ClassDtBaseConnect clReport = new ClassDtBaseConnect();
Int64 currLogUserId = Convert.ToInt64(Session["session_log_id"]);
int currLogUserType = Convert.ToInt32(Session["session_usertype"]);
string logfield = "";
string selStartdate = txtStartDate.Text.Trim();
string selEnddate = txtEndDate.Text.Trim();
string StartDateString = "";
string EndDateString = "";
DateTime date = new DateTime();
DateTime date1 = new DateTime();
DateTime date2 = new DateTime();
if (selStartdate != "" && selEnddate != "")
{
date = DateTime.ParseExact(selStartdate, "dd/MM/yyyy", null);
StartDateString = date.ToString("yyyy/MM/dd");
date1 = DateTime.ParseExact(selEnddate, "dd/MM/yyyy", null);
EndDateString = date1.ToString("yyyy/MM/dd");
logfield = StartDateString + "to" + EndDateString;
}
int owner = 0;
if (ddlowner.SelectedIndex != 0)
{
owner = Convert.ToInt32(ddlowner.SelectedValue);
logfield = logfield + "," + ddlowner.SelectedItem.Text;
}
string queryStr = "";
if (currLogUserType != 1)
{
}
else
{
//queryStr = "SELECT distinct inq.inquiry_id, inq.company,log.subject, log.medium, log.subject_type, log.comments,log.date,country.country_name FROM crm_inquiry_perticipant inq INNER JOIN crm_inquiry_log_details log ON inq.inquiry_id = log.inquiry_id Inner join crm_countries country ON inquiry.country=country.country_id order by inq.inquiry_id";
queryStr= "SELECT log.date,log.log_inquiry_id,inq.company,inq.inquiry_id,log.subject,log.medium,log.subject_type,log.comments,logg.name FROM crm_inquiry_log_details log "
+ "INNER JOIN crm_inquiry_perticipant inq ON inq.inquiry_id = log.inquiry_id"
+ " INNER JOIN crm_login logg ON inq.inquiry_owner=logg.log_id "
+ " WHERE "
+ "(( " + owner + "=0) OR (inq.inquiry_owner=" + owner + "))" +
// " (('" + StartDateString + "'='') OR (log.date BETWEEN '" + StartDateString + "' AND '" + EndDateString + "')) " +
"order by log_inquiry_id desc";
}
ClassDtBaseConnect clsDtResult = new ClassDtBaseConnect();
DataTable dt = clsDtResult.GetDataTable(queryStr);
ExportToExcel(dt);
}
catch { }
}