this is my aspx page code
DefaultContainerName="StockyEntities" EnableFlattening="False" EntitySetName="Buys"
Include="Supplier" Where="(it.OrganizationID=@OrganizationID) AND (it.BuyDate >= @DateFrom or @DateTo IS NULL ) AND ( it.BuyDate <= @DateTo or @DateTo IS NULL ) AND (it.InvoiceNumber=@BuyID or @BuyID IS NULL) AND (it.Supplier.SupplierName=@Supplier or @Supplier IS NULL)"
EntityTypeFilter="Buy">
Type="Int32" />
and this is the code in aspx.cs file code ... so what can i do ..... please help me quicky ...
DateTime fromDate; DateTime.TryParseExact(FromDateTextBox.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out fromDate); //if the control is null it retruns Minvalue (1/1/0001 12:00:00 AM)
DateTime toDate; DateTime.TryParseExact(ToDateTextBox.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out toDate); //if the control is null it retruns Minvalue (1/1/0001 12:00:00 AM)
string BuyId = BuyIDTextBox.Text;
string SupplierName = SupplierTextBox.Text;
string fromDateString = fromDate.ToString();//to current culture format
string toDateString = toDate.ToString();//to current culture format
BuyEntityDataSource.WhereParameters["DateTo"].DefaultValue = toDateString;
BuyEntityDataSource.WhereParameters["DateFrom"].DefaultValue = fromDateString;
BuyEntityDataSource.WhereParameters["Supplier"].DefaultValue = SupplierName;
BuyEntityDataSource.WhereParameters["BuyID"].DefaultValue = BuyId;
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sandeep Singh ShekhawatPosted May 21, 2013, 11:16 AM
DateTime fromDate;
DateTime.TryParseExact(FromDateTextBox.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out fromDate);
DateTime toDate;
DateTime.TryParseExact(ToDateTextBox.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out toDate);
When you try to assign a DateTime to the null literal in the C# language, The compiler will give an error "Cannot convert null to System.DateTime". The null value in the language is only used on reference types. It can tell the CLR that a reference doesn't point at anything. The DateTime type never points at anything. Instead, it stores all its data in place of that reference, directly in the variable itself.
So declare nullable type variable and assign value for example
DateTime newFromDate ;
DateTime.TryParseExact(FromDateTextBox.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out newFromDate );
DateTime newToDate ;
DateTime.TryParseExact(ToDateTextBox.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out newToDate );
DateTime? fromDate = null;
DateTime? toDate= null;
if (newFromDate != DateTime.MinValue)
{
fromDate = newFromDate ;
}
if (newToDate != DateTime.MinValue)
{
toDate = newToDate ;
}
Now you can use both variable fromDate and toDate to pass in EF