Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Thursday, 30 April 2009

Crystal Report Printing in ASP.Net

function ShowCreprt()
{
string str_sql=null;
DataSet DsMain = new DataSet();
CrystalDecisions.CrystalReports.Engine.ReportDocument rp;

string reportPath = Server.MapPath("LogReport.rpt"); //Set path of Crystal Report

rp = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); // Object of Report Document

sql = "Select l_name as username,'' as sno, userdetail.user_ip as uip from userdetail Where userdetail.user_id=" + int_loginID + " order by servertime";

//in DsMain i fill records as per above query

rp.FileName = reportPath;
rp.SetDataSource(dsmain.Tables[0]);

crviewer.ReportSource = rp;
//I have crviewer control on my page


}

Tuesday, 28 April 2009

Reading/Writing Excel without Office.

//reading and writing into xls file without install office at local machine
OleDbConnection objconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/DataUser/User" + loginfolder + "/" + excelsheetname + ".xls") + ";Extended Properties=Excel 8.0;");
objconn.Open();

DataTable dtSheetSchema = new DataTable();
OleDbCommand ObjCmd;

string Str_Sql;
dtSheetSchema = objconn.GetSchema("Tables"); // for getting all table list

string Str_SheetName = "[" + workbookname + "]";
ObjCmd = new OleDbCommand();
ObjCmd.Connection = objconn;
//this code using for preparing sheet columns headings
if (k == 0)
{
Str_Sql = "Select " + str_header.ToString().Substring(0, str_header.Length - 1) + " into " + Str_SheetName + " From [Sheet1$]";
ObjCmd.CommandText = Str_Sql;
ObjCmd.ExecuteNonQuery();
}

Str_Sql = "";
//this code using for insert value in sheet columns
Str_Sql = "Insert into " + Str_SheetName + "(" + str_columns.ToString().Substring(0, str_columns.Length - 1) + ") values(" + str_colvalue.ToString().Substring(0, str_colvalue.Length - 1) + ")";
ObjCmd.CommandText = Str_Sql;
ObjCmd.ExecuteNonQuery();
str_colvalue.Remove(0, str_colvalue.Length);
}
objconn.Close();