Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           string str = "Select sponcorid,leftcount,rightcount,totcount,pair,createddate from Payout_Master Where createddate Between '" + Calendar1.SelectedDate.ToString("yyyy-MM-dd") + "' And '" + Calendar1.SelectedDate.ToString("yyyy-MM-dd") + "'";
               //string str = "SELECT sponcorid,leftcount,rightcount,totcount,pair,createddate FROM Payout_Master WHERE createddate='" + Calendar1.SelectedDate.ToShortDateString() + "'";
               com = new SqlCommand(str, con);
               com.CommandType = CommandType.Text;
               da = new SqlDataAdapter(com);
               DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    gvUserInfo.DataSource = dt;
                    gvUserInfo.DataBind();
                }

       }

}

error:

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Posted
Updated 8-Feb-13 22:37pm
v4
Comments
[no name] 9-Feb-13 3:09am    
What error ?
[no name] 9-Feb-13 3:45am    
what error are you getting????????? :-(
Bhushan Shah1988 9-Feb-13 3:56am    
what is the error??

Without your error message it's difficult to be precise, but it is likely that the problem is that ToShortDateString is culture sensitive, and the information it returns will depend on how the computer you are running on is configured. Since SQL prefers it's date in yyyy-MM-dd format, try using ToString instead:
C#
string str = "Select sponcorid,leftcount,rightcount,totcount,pair,createddate from Payout_Master Where createddate Between '" + Calendar1.SelectedDate.ToString("yyyy-MM-dd") + "' And '" + Calendar1.SelectedDate.ToString("yyyy-MM-dd") + "'";
However, I doubt if your query will return may records, given that both dates are the same! Did you mean to use two Calender objects?
 
Share this answer
 
Comments
sumit kausalye 9-Feb-13 4:22am    
No it still gives me the same error.
OriginalGriff 9-Feb-13 4:27am    
What error message?
datetime dt=Calendar1.SelectedDate.ToShortDateString();

C#
string str = "Select sponcorid,leftcount,rightcount,totcount,pair,createddate from Payout_Master Where createddate Between '" + dt + "' And '" + dt + "'";


put a break point at datetime dt check the date format.
 
Share this answer
 
v2
Comments
sumit kausalye 9-Feb-13 4:25am    
its give same error
srikanth pachava 9-Feb-13 4:29am    
sumit calender1 resembles textbox(if u r using ajax calender extender) or calender control?
srikanth pachava 9-Feb-13 4:46am    
write a condition if(calender1.selectedvalues is null) then fetch the min date from the table and max date is also same.

instead createddate between write convert(varchar(10),createddate,110) between
srikanth pachava 9-Feb-13 4:47am    
note the format which date is taking. from the calender and we need write the code instead of 110 to any format.
it is stating that you are giving date but it is not match with database date type so you need to convert date to required type and then place in query may solve your problem..
 
Share this answer
 

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