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:52
Edited 16 Nov '12 - 12:01

Comments
DinoRondelly - 16 Nov '12 - 17:56
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:03
It might works! +5
manoj kumar choubey - 16 Nov '12 - 23:26
+5
thanks it give me this problem

Conversion failed when converting datetime from character string.
  Permalink  
Comments
Rohit Shrivastava - 16 Nov '12 - 18:46
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 Sergey Alexandrovich Kryukov 414
1 Arun Vasu 253
2 OriginalGriff 200
3 CPallini 163
4 Aarti Meswania 158
0 Sergey Alexandrovich Kryukov 10,169
1 OriginalGriff 7,749
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 3,089


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