Click here to Skip to main content
12,076,925 members (49,154 online)
Rate this:
 
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 12:52pm
Edited 16-Nov-12 13:01pm
Maciej Los213.9K
v2
Comments
DinoRondelly 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 16-Nov-12 18:03pm
   
It might works! +5
manoj kumar choubey 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160212.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2016
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