Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 Los136.3K
v2
Comments
DinoRondelly at 16-Nov-12 17:56pm
   
What type of field is date?
is it a datetime field?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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  
v4
Comments
Maciej Los at 16-Nov-12 18:03pm
   
It might works! +5
manoj kumar choubey at 16-Nov-12 23:26pm
   
+5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

thanks it give me this problem

Conversion failed when converting datetime from character string.
  Permalink  
Comments
Rohit Shrivastava at 16-Nov-12 18:46pm
   
use convert method to convert string to datetime updated the solution.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
0 Sergey Alexandrovich Kryukov 839
1 OriginalGriff 400
2 CPallini 275
3 George Jonsson 191
4 Richard Deeming 145
0 OriginalGriff 5,450
1 Sergey Alexandrovich Kryukov 4,532
2 CPallini 4,500
3 George Jonsson 3,102
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100