944,035 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 2200
  • C# RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Oct 22nd, 2009
0
Re: Binding data from dateTimePicker to a variable
Actually post the complete code. Are you using an OleDb or ODBC driver? OleDb supports named parameters depending on the driver but ODBC does not. Post where you are instantiating the database connection.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Oct 22nd, 2009
1
Re: Binding data from dateTimePicker to a variable
Oh, try something like this:

C# Syntax (Toggle Plain Text)
  1. private void button2_Click(object sender, EventArgs e)
  2. {
  3. const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;";
  4. const string query = "Select * From Invoice Where (InHomeDate BETWEEN @Date1 and @Date2)";
  5. using (SqlConnection conn = new SqlConnection(connStr))
  6. {
  7. conn.Open();
  8. using (SqlCommand cmd = new SqlCommand(query, conn))
  9. {
  10. cmd.Parameters.Add(new SqlParameter("@Date1", SqlDbType.DateTime)).Value = DateTime.Today.AddDays(-180);
  11. cmd.Parameters.Add(new SqlParameter("@Date2", SqlDbType.DateTime)).Value = DateTime.Today;
  12. using (SqlDataReader dr = cmd.ExecuteReader())
  13. {
  14. DataTable dt = new DataTable();
  15. dt.Load(dr);
  16. dataGridView1.DataSource = dt;
  17. }
  18. }
  19. }
  20. }
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Oct 22nd, 2009
0
Re: Binding data from dateTimePicker to a variable
Click to Expand / Collapse  Quote originally posted by sknake ...
Oh, try something like this:

C# Syntax (Toggle Plain Text)
  1. private void button2_Click(object sender, EventArgs e)
  2. {
  3. const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;";
  4. const string query = "Select * From Invoice Where (InHomeDate BETWEEN @Date1 and @Date2)";
  5. using (SqlConnection conn = new SqlConnection(connStr))
  6. {
  7. conn.Open();
  8. using (SqlCommand cmd = new SqlCommand(query, conn))
  9. {
  10. cmd.Parameters.Add(new SqlParameter("@Date1", SqlDbType.DateTime)).Value = DateTime.Today.AddDays(-180);
  11. cmd.Parameters.Add(new SqlParameter("@Date2", SqlDbType.DateTime)).Value = DateTime.Today;
  12. using (SqlDataReader dr = cmd.ExecuteReader())
  13. {
  14. DataTable dt = new DataTable();
  15. dt.Load(dr);
  16. dataGridView1.DataSource = dt;
  17. }
  18. }
  19. }
  20. }
Hey!! Thanks a lot, it works! \:d/ - I get no error
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beginerC# is offline Offline
20 posts
since Oct 2009
Oct 22nd, 2009
0
Re: Binding data from dateTimePicker to a variable
the code was
C# Syntax (Toggle Plain Text)
  1. mySqlCommand.Parameters.Add(new SqlParameter("@date1", SqlDbType.DateTime));
  2. mySqlCommand.Parameters["@date1"].Value = dateTimePicker1.Value;
for each one @date
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beginerC# is offline Offline
20 posts
since Oct 2009
Oct 22nd, 2009
0
Re: Binding data from dateTimePicker to a variable
Please mark as SOLVED unless you are still having trouble.
Reputation Points: 341
Solved Threads: 233
Posting Shark
DdoubleD is offline Offline
984 posts
since Jul 2009
Nov 3rd, 2009
0
Re: Binding data from dateTimePicker to a variable
Sorry, i forgot to mark this as solved.
Thanks a lot, sknake!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
beginerC# is offline Offline
20 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: How to use trigger in C#
Next Thread in C# Forum Timeline: make an installer for c# apps





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC