Posts

Showing posts from 2015

Export DataTable or DataSet to CSV or XML

using System ; using System.Collections.Generic ; using System.Configuration ; using System.Data ; using System.Data.SqlClient ; using System.IO ; using System.Linq ; using System.Text ; using System.Web ; using System.Web.UI ; using System.Web.UI.WebControls ; using System.Xml.Serialization ; public partial class ExportReservationInfo : System . Web . UI . Page { #region Events protected void Page_Load ( object sender , EventArgs e ) { lblMsg . Text = "" ; if ( Page . IsPostBack ) { } } protected void btnExportToCSV_Click ( object sender , EventArgs e ) { string strReservationId = txtReservationId . Text . Trim (); DataSet ds ; try { int ReservationId = Convert . ToInt32 ( strReservationId ); ds = ExecuteQuery ( ReservationId ); //Export to CSV ExportToSpr...

How to SELECT WHERE NOT EXIST using LINQ?

/* #Where EXISTS ===================== */ from p in tblProjectInfo where tblProjectFundingCommitment . Any ( pfc =>( pfc . ProjectId == p . Id )&&( pfc . FundSourceId == 44 )) select p tblProjectInfo . Where ( p => ( tblProjectFundingCommitment . Any ( pfc => (( pfc . ProjectId == p . Id ) && ( pfc . FundSourceId == 44 ))) ) ) //--With Optional Parameters //--------------------------- int intIsUnderADP = 0 / 1 / 2 ; //we will skip comaping if value is 2(not a boolean) bool isUnderADP = Convert . ToBoolean ( intIsUnderADP ); int managingDPId = [ any integer value starts from 0 ]; //we will skip comaping if 0 tblProjectInfo . Where ( p => (( intIsUnderADP == 0 || intIsUnderADP == 1 ) ? p . IsUnderADP == isUnderADP : true ) && ( context . tblProjectFundingCommitment . Any ( pfc => (( pfc . Pr...