| | |
Binding data from dateTimePicker to a variable
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 14
Reputation:
Solved Threads: 0
Hi!
I have a form with two dateTimePickers (first with date of one month ago, and the secod with current date), a dataGridView and a button.
When i click the button i want to populate the dataGridView, but only between date1 and date2
I get this error "Must declare the scalar variable "@date1".
Can anyone help me, please?
I have a form with two dateTimePickers (first with date of one month ago, and the secod with current date), a dataGridView and a button.
When i click the button i want to populate the dataGridView, but only between date1 and date2
C# Syntax (Toggle Plain Text)
mySqlCommand = con.CreateCommand(); mySqlCommand.CommandText = "SELECT * FROM MyTable WHERE (MyDate BETWEEN @date1 AND @date2)"; mySqlCommand.Parameters.Add("@date1", SqlDbType.Char); mySqlCommand.Parameters["@date1"].Value = dateTimePicker1.Text.ToString(); mySqlCommand.Parameters.Add("@date2", SqlDbType.Char); mySqlCommand.Parameters["@date2"].Value = dateTimePicker2.Text.ToString()
Can anyone help me, please?
0
#2 Oct 21st, 2009
What type of SQL Connection is that? MSSQL? MySQL? Why are you declaring the command parameter as a char if it is a date value?
0
#4 Oct 22nd, 2009
You need to change it. Using the >= and <= operators on strings doesn't always work the same as dates...
0
#6 Oct 22nd, 2009
With mySQL you need to use "?" for parameter names. Try changing this line:
To:
C# Syntax (Toggle Plain Text)
mySqlCommand.CommandText = "SELECT * FROM MyTable WHERE (MyDate BETWEEN @date1 AND @date2)";
To:
C# Syntax (Toggle Plain Text)
mySqlCommand.CommandText = "SELECT * FROM MyTable WHERE (MyDate BETWEEN ? AND ?)";
•
•
Join Date: Oct 2009
Posts: 14
Reputation:
Solved Threads: 0
0
#7 Oct 22nd, 2009
•
•
•
•
With mySQL you need to use "?" for parameter names. Try changing this line:
C# Syntax (Toggle Plain Text)
mySqlCommand.CommandText = "SELECT * FROM MyTable WHERE (MyDate BETWEEN @date1 AND @date2)";
To:
C# Syntax (Toggle Plain Text)
mySqlCommand.CommandText = "SELECT * FROM MyTable WHERE (MyDate BETWEEN ? AND ?)";
0
#8 Oct 22nd, 2009
I give up 
I don't know anything about mySQL. Sorry I couldn't be of more help. I try to stick with MSSQL.

I don't know anything about mySQL. Sorry I couldn't be of more help. I try to stick with MSSQL.
![]() |
Similar Threads
- Nested Data Source Binding error only when List is empty (C#)
- Storing data from mysql as variable? (PHP)
- How to bind data from Gridview to a Variable (ASP.NET)
- How to read the data from Table Variable (MS SQL)
- How much data can a post variable hold? (PHP)
- thread-safe variable (C)
- variable to handle large integer (C)
- AnsiString Template Data Return Problem Builder 6 (C++)
Other Threads in the C# Forum
- Previous Thread: convert amount to words
- Next Thread: make an installer for c# apps
Views: 675 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast button c# chat check checkbox class client code combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms ftp function gcd gdi+ http httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion prime programming radians regex remote remoting resource saving serialization server sleep socket sql statistics stream string tcp text textbox time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






