I am a beginner at C# .net and my question is about creating a program in C# which shows the result from a small database for each date selected from month calendar. For example I choose 25/5/2013
and it shows in a richtextbox appointment with john smith.
I get the date with
this.richTextBox1.Text = monthCalendar1.SelectionRange.Start.Date.ToShortDateString();
but when I try to show the row I want, the program crashes. I used this code to show it in datagrid
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=event_agenda;Integrated Security=True");
DataTable dt = new DataTable();
SqlDataAdapter SDA = new SqlDataAdapter("Select * from event where date_event =" + monthCalendar1.SelectionRange.Start.Date.ToShortDateString(), conn);
SDA.Fill(dt);
dataGridView1.DataSource = dt;
it doesn't show anything
But with this it shows all rows in database without problem
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=event_agenda;Integrated Security=True");
DataTable dt = new DataTable();
SqlDataAdapter SDA = new SqlDataAdapter("Select * from event", conn);
SDA.Fill(dt);
dataGridView1.DataSource = dt;
My database has a table event and two columns: date_event
(varchar(9)
) and notes
(varchar(150)
)
Where is my mistake? I would appreciate if someone helps me