Skip to content
Loading
  • Amit Gupta
    +1
    Your condition in both the snippet are not identical, can you write your condition in simple algorithm
    +1
  • Amit Gupta
    +1
    Damm !! You haven't expressed your condition
     
    1. var query = "select dateColumn from tablename;    
    2. var value = cmd.ExecuteScalar();     
    3.     
    4. //Assuming somehow above has been achieved    
    5.     
    6. var DValue = value== DbNull.Value?DateTime.MinValue : Convert.ToDateTime(value);    
    7.   
    8. vrijemeodjaveDateTimePicker.Value = DValue;  
    9. vrijemeodjaveDateTimePicker.Value = DValue == System.DateTime.MinValue ? DateTime.Parse("2018-01-01 00:00:00") : DValue;    
    I had made modification, hope thats what you are looking for 
    +1
  • Amit Gupta
    +1
    It was just asking that we got value in object and we coded for string.
    Here's the updated snippet
    1. ....       
    2. radnikComboBox.Text = radnik;        
    3.                //vrijemeprijaveDateTimePicker.Value = Convert.ToDateTime(prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);
    4. // don't convert it to datetime (as you said, it may be null)      
    5. var stringValue = (prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);        
    6.       
    7. // not checking stringValue is null or not      
    8. var dateValue = string.IsNullOrEmpty(Convert.ToString(stringValue))?DateTime.MinValue:Convert.ToDateTime("2018-01-01 00:00:00");      
    9.       
    10. // now, datevalue is the new value for datepicker                    
    11.  vrijemeodjaveDateTimePicker.Value = dateValue;     
    +1
  • Amit Gupta
    +1
    app no ??
     
    where's the app no, you haven't posted the code that contains app no. 
    +1
  • Amit Gupta
    +1
    App not start?
     
    What does it mean? What error you are getting, show that error.
     
    I suggest you to clean and rebuild the project and then try, sometimes that works too.. 
    +1
  • Amit Gupta
    +1
    You want like
    if(sqlcolumndate = null)
    datepicker.value = "2018-01-01 00:00:00"
    else
    datepicker.value = sqlcolumndate
     
    Is it like that? or something else. If yes, then I believe that you can apply this logic
    +1
  • Amit Gupta
    +1
    God !!
     
    Try this
    1. ....         
    2. radnikComboBox.Text = radnik;          
    3.                //vrijemeprijaveDateTimePicker.Value = Convert.ToDateTime(prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);    
    4. // don't convert it to datetime (as you said, it may be null)        
    5. var stringValue = (prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);
    6. // now, datevalue is the new value for datepicker     
    7. if(string.IsNullOrEmpty(Convert.ToString(stringValue)))                   
    8.  vrijemeodjaveDateTimePicker.Value = dateValue;
    +1
  • Amit Gupta
    +1
    Please be specific to what you are asking for. Don't get confused while asking your doubts, be prepared and relax.
     
    Here's the code
    1. ....           
    2. radnikComboBox.Text = radnik;            
    3.                //vrijemeprijaveDateTimePicker.Value = Convert.ToDateTime(prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);
    4. // don't convert it to datetime (as you said, it may be null)          
    5. var stringValue = (prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);
    6. // now, datevalue is the new value for datepicker       
    7. vrijemeodjaveDateTimePicker.Value =  string.IsNullOrEmpty(Convert.ToString(stringValue))? Convert.ToDateTime("2018-01-01 00:00:00"  : Convert.ToDateTime(stringValue)
    +1
  • Amit Gupta
    +1
    You had applied the property (MinDate and MaxDate) in datetimepicker property, remove them to resolve this issue
    +1
  • Amit Gupta
    +1
    Did you got your issue resolved?
    +1
  • Amit Gupta
    +1
    Don't you removed the property of mindate and max date in property window?
    +1
  • +1
    Is this solution
    1. vrijemeodjaveDateTimePicker.Value =  DBNull.Value.Equals("2018-01-01 00:00:00") ? emptydate : vrijemeodjaveDateTimePicker.Value; 
    Have one problem...when datagrid column have value in datetimepicker he show me 2018-01-01 00:00:00.
     
    I need to show value from cell in datetimepicker if have, is is null to show 2018-01-01 00:00:00
    +1
  • 0
    I need this condition
     
     
    1. private DateTime emptydate = DateTime.Parse("2018-01-01 00:00:00");   
     
    Here in selection changed
     
    1. private void prijava_radnikaDataGridView_SelectionChanged(object sender, EventArgs e)  
    2.        {  
    3.            if (prijava_radnikaDataGridView.SelectedRows.Count > 0 )  
    4.   
    5.            {  
    6.   
    7.                string id = prijava_radnikaDataGridView.CurrentRow.Cells["dataGridViewTextBoxColumn1"].FormattedValue.ToString();  
    8.               string radnik = prijava_radnikaDataGridView.CurrentRow.Cells["dataGridViewTextBoxColumn9"].FormattedValue.ToString();  
    9.                string redni_broj = prijava_radnikaDataGridView.CurrentRow.Cells["redni_broj"].FormattedValue.ToString();  
    10.              

    11.                redni_brojTextBox.Text = redni_broj;  
    12.                idPrijavaTextBox.Text = id;  
    13.                radnikComboBox.Text = radnik;  
    14.                vrijemeprijaveDateTimePicker.Value = Convert.ToDateTime(prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);  
    15.              
    16.    //this line                  vrijemeodjaveDateTimePicker.Value = vrijemeodjaveDateTimePicker.Value == System.DateTime.MinValue ? DateTime.Parse("2018-01-01 00:00:00") : vrijemeodjaveDateTimePicker.Value;  
    17.   
    18.            }  
    19.        } 
     
    0
  • 0
    I hope you understand
    0
  • 0
    This is my code
     Line 17 is problem...
    Code working fine...but line 17 is problem...I want to write that line...: IF is sql cell null to show empty value in data greed and 2018-01-01 00:00:00 in datetimepicker
    1. private void prijava_radnikaDataGridView_SelectionChanged(object sender, EventArgs e)  
    2.        {  
    3.             
    4.            if (prijava_radnikaDataGridView.SelectedRows.Count > 0 )  
    5.   
    6.            {  
    7.   
    8.                string id = prijava_radnikaDataGridView.CurrentRow.Cells["dataGridViewTextBoxColumn1"].FormattedValue.ToString();  
    9.               string radnik = prijava_radnikaDataGridView.CurrentRow.Cells["dataGridViewTextBoxColumn9"].FormattedValue.ToString();  
    10.                string redni_broj = prijava_radnikaDataGridView.CurrentRow.Cells["redni_broj"].FormattedValue.ToString();  
    11.                  
    12.   
    13.                redni_brojTextBox.Text = redni_broj;  
    14.                idPrijavaTextBox.Text = id;  
    15.                radnikComboBox.Text = radnik;  
    16.                vrijemeprijaveDateTimePicker.Value = Convert.ToDateTime(prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);  
    17.                vrijemeodjaveDateTimePicker.Value = vrijemeodjaveDateTimePicker.Value == System.DateTime.MinValue ? DateTime.Parse("2018-01-01 00:00:00") : vrijemeodjaveDateTimePicker.Value;  
    18.   
    19.            }  
    20.        } 
    0
  • 0
    I not need conectiomn etc...
     
    1. var query = "select dateColumn from tablename;      
    2. var value = cmd.ExecuteScalar();       
    3.       
    4. //Assuming somehow above has been achieved      
    5.       
    6. var DValue = value== DbNull.Value?DateTime.MinValue : Convert.ToDateTime(value);      
    7.     
    8. vrijemeodjaveDateTimePicker.Value = DValue;    
    9. vrijemeodjaveDateTimePicker.Value = vrijemeodjaveDateTimePicker.Value == System.DateTime.MinValue ? DateTime.Parse("2018-01-01 00:00:00") : vrijemeodjaveDateTimePicker.Value;    
     I just need line 9...if is column value null to put in datetimepicker value 2018-01-01 00:00:00
     
    and in datagrid empty cell
    0
  • 0
    This is a possible solution but have one error
     
    Severity Code Description Project File Line Suppression State
    Error CS1503 Argument 1: cannot convert from 'object' to 'string' prijava_radnika
     
    line 10 on your code
    1. ....     
    2. radnikComboBox.Text = radnik;      
    3.                //vrijemeprijaveDateTimePicker.Value = Convert.ToDateTime(prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);
    4. // don't convert it to datetime (as you said, it may be null)    
    5. var stringValue = (prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);
    6. // not checking stringValue is null or not    
    7. var dateValue = string.IsNullOrEmpty(stringValue)?DateTime.MinValue:Convert.ToDateTime("2018-01-01 00:00:00");
    8. // now, datevalue is the new value for datepicker                  
    9.  vrijemeodjaveDateTimePicker.Value = dateValue;
    0
  • 0
    No...that is not solution....app no start if have null value in column...when delete that column...code working fine...what is error?
     
    Now when column value is null app not start, if I delete that row, app work, but datetimepicker is always 2018-01-01 00:00:00
    0
  • 0
    I try now...app work but in datetimepicker is value always 2018-01-01 00:00:00
    0
  • 0
    Complete column have value 2018-01-01 00:00:00...that value need only if is column null
    0
  • 0
    I try now...work app...after clean...app work but in datetimepicker is value always 2018-01-01 00:00:00 ? Why? I need that value only if is column value null
    0
  • 0
    I try now...work app...after clean...app work but in datetimepicker is value always 2018-01-01 00:00:00 ? Why? I need that value only if is column value null
    0
  • 0
    Yes thats it!!!! Bravo
     
    You want like
     
    if(sqlcolumndate = null)
    datepicker.value = "2018-01-01 00:00:00"
    else
    datepicker.value = sqlcolumndate
    Is it like that? or something else. If yes, then I believe that you can apply this logic
     
    Where to put this code?
    1. var stringValue = (prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);  
    2.   
    3.                // not checking stringValue is null or not        
    4.                var dateValue = string.IsNullOrEmpty(Convert.ToString(stringValue)) ? DateTime.MinValue : Convert.ToDateTime("2018-01-01 00:00:00");  
    5.   
    6.                // now, datevalue is the new value for datepicker                      
    7.                vrijemeodjaveDateTimePicker.Value = dateValue;
    0
  • 0
    This solution not work...another? Before this work...now not...
    1. ....           
    2. radnikComboBox.Text = radnik;            
    3.                //vrijemeprijaveDateTimePicker.Value = Convert.ToDateTime(prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);
    4. // don't convert it to datetime (as you said, it may be null)          
    5. var stringValue = (prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn2"].Value);
    6. // now, datevalue is the new value for datepicker       
    7. if(string.IsNullOrEmpty(Convert.ToString(stringValue)))                     
    8.  vrijemeodjaveDateTimePicker.Value = dateValue; 
     
    0
  • 0
    I find error
    1. Activated   Event   Time    Duration    Thread  
    2.     Exception thrown: 'System.ArgumentOutOfRangeException' in System.Windows.Forms.dll ("Value of '1.1.0001. 00:00:00' is not valid for 'Value'. 'Value' should be between 'MinDate' and 'MaxDate'.")   14.33s      [17640]   
     
    0
  • 0
    This is error
    1. Activated   Event   Time    Duration    Thread    
    2.     Exception thrown: 'System.ArgumentOutOfRangeException' in System.Windows.Forms.dll ("Value of '1.1.0001. 00:00:00' is not valid for 'Value'. 'Value' should be between 'MinDate' and 'MaxDate'.")   14.33s      [17640]
    0
  • 0
    How to do this?
     
    You had applied the property (MinDate and MaxDate) in datetimepicker property, remove them to resolve this issue 
    0
  • 0
    No, I am not solve the problem...
    0
  • 0
    No, how t do that?
     
     Don't you removed the property of mindate and max date in property window?
    0
  • Amit Gupta
    0
    Before looking and do repair of the code, one should have some basic knowledge of fundamentals of coding, what you are going to do, what output should be generated. The code which I gave you yesterday is what you have expected. You just need to remove the min and max date property. Don't mix other's code that cause more confusing scenario.
    0
  • 0
    Please help me to solve the problem
     
    1. vrijemeodjaveDateTimePicker.Value =  DBNull.Value.Equals("2018-01-01 00:00:00") ? emptydate : vrijemeodjaveDateTimePicker.Value;  
     I need value from datagrid show in datetimepicker, if is null show 2018-01-01 00:00:00
     
    What to do?
    0
  • -1
    Yes
    -1
  • -1
    I am looking on the internet and create cod...but need to repair him
     
    I need that simple code...if hvae value in cell to show in datetimepicker if  is value null to show 2018-01-01 00:00:00
     
    Why is complicate?
    -1
  • -1
    Some easy solution?
    -1