Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Friends,

i have store procedure that retrieve date from database here is SP :-
SQL
public DataSet GetOrderList(int OrderID, DateTime OrderDate,  string OrderStatus)
    {
        Database db = new SqlDatabase(this.ConnectionString);
        using (DbCommand objcmd = db.GetStoredProcCommand("dbo.GetOrderList"))
        {
            if (OrderID == null)
                db.AddInParameter(objcmd, "@OrderID", DbType.Int32, DBNull.Value);
            else
                db.AddInParameter(objcmd, "@OrderID", DbType.Int32, OrderID);

            if (OrderDate == null)
                db.AddInParameter(objcmd, "@OrderDate", DbType.Date, DBNull.Value);
            else
                db.AddInParameter(objcmd, "@OrderDate", DbType.Date, OrderDate);

            if (OrderStatus == null)
                db.AddInParameter(objcmd, "@OrderStatus", DbType.String, DBNull.Value);
            else
                db.AddInParameter(objcmd, "@OrderStatus", DbType.String, OrderStatus);

            DataSet ds = db.ExecuteDataSet(objcmd);
            return ds;
        }
    }



now i bind data like that but :-
C#
private void BindData()
    {
        DateTime? dt = null;

        try
        {
            BindData(null, null, 0, null, null);
        }
        catch (Exception ex)
        {
            lblerror.Visible = true;
            lblerror.InnerText = ex.Message.ToString();
        }
    }

C#
private void BindData(string SortExpression, string SortDirection, int OrderID, DateTime OrderDate, string OrderStatus)
    {
            DatabaseHelper db = new DatabaseHelper();
            DataSet ds = db.GetOrderList(OrderID, OrderDate, OrderStatus);

            if (SortDirection != null && SortExpression != null)
            {
                DataView DView = new DataView(ds.Tables[0]);
                DView.Sort = SortExpression + " " + SortDirection;
                GrdOrder.DataSource = DView;
            }
            else
            {
                GrdOrder.DataSource = ds.Tables[0];
                GrdOrder.DataBind();
            }
     }


now what i pass when i datetime is null..
Any one other way to bind the data..with this arguments.

Thank You To All
Posted
Comments
Sandeep Mewara 27-Aug-12 7:19am    
Not clear.

You say you bind the datetime field to grid when it is null? Does not make sense.
Your code shared too does not explain much.

Please use 'Improve Question' link and edit/update your question.
Yatin chauhan 27-Aug-12 8:33am    
Thank You Sandeepsir for reply.
i found the problem and get the solution now its run correct.
Yatin chauhan 27-Aug-12 8:45am    
here in my code DateTime? dt = null;
not allow null value so that is the problem.

You can do something like this:
C#
DateTime dt = DateTime.MinValue;


You cannot set null values for DateTime.

Hope it helps.
 
Share this answer
 
Comments
Yatin chauhan 28-Aug-12 0:59am    
Yes i set min value and check like that :-
if (OrderDate.Equals(DateTime.MinValue))
db.AddInParameter(objcmd, "@OrderDate", DbType.Date, DBNull.Value);
else
db.AddInParameter(objcmd, "@OrderDate", DbType.Date, OrderDate);


now its working fine..
Thank You Christian Amado
OP resolved the issue by himself.

OP posted:
here in my code DateTime? dt = null; not allow null value so that is the problem.
 
Share this answer
 
v2
Comments
Yatin chauhan 28-Aug-12 0:59am    
Thank You Sandeepsir Mewara

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900