Click here to Skip to main content
Sign Up to vote bad
good
See more: C#
SqlDataAdapter cmd = new SqlDataAdapter("select * from calender where date= " + monthCalendar1.SelectionRange.Start , con);
            
            SqlCommandBuilder cb = new SqlCommandBuilder(cmd);
            DataSet ds = new DataSet();
            cmd.Fill(ds);
 

            dataGridView1.DataSource = ds.Tables[0];
 

can solve this problem to show the information when select the date from calender
Posted 16-Nov-12 11:52am
Edited 16-Nov-12 12:01pm
Maciej Los60.3K

Comments
DinoRondelly - 16-Nov-12 17:56pm
What type of field is date? is it a datetime field?

3 solutions

Change
 
SqlDataAdapter cmd = new SqlDataAdapter("select * from calender where date= " + monthCalendar1.SelectionRange.Start , con);
to
SqlDataAdapter cmd = new SqlDataAdapter("select * from calender where date= CAST('" + monthCalendar1.SelectionRange.Start.ToString() + "' as datetime)" , con);
 
please refer http://msdn.microsoft.com/en-us/library/ms187928.aspx[^] to cast string to datetime for more parameters.
I would suggest to use parameters. You can find many samples for creating command with parameters.
 
Hope this helps.
  Permalink  
Comments
Maciej Los - 16-Nov-12 18:03pm
It might works! +5
manoj kumar choubey - 16-Nov-12 23:26pm
+5
thanks it give me this problem

Conversion failed when converting datetime from character string.
  Permalink  
Comments
Rohit Shrivastava - 16-Nov-12 18:46pm
use convert method to convert string to datetime updated the solution.
thanks sooooooo much it solved
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 544
1 Michael Haephrati 390
2 OriginalGriff 233
3 Ron Beyer 220
4 samadhan_kshirsagar 219
0 Sergey Alexandrovich Kryukov 6,959
1 Prasad_Kulkarni 3,689
2 OriginalGriff 3,402
3 _Amy 3,332
4 CPallini 2,950


Advertise | Privacy | Mobile
Web02 | 2.6.130617.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid