| | |
Binding data from dateTimePicker to a variable
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
0
#11 Oct 22nd, 2009
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.
1
#12 Oct 22nd, 2009
Oh, try something like this:
C# Syntax (Toggle Plain Text)
private void button2_Click(object sender, EventArgs e) { const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;"; const string query = "Select * From Invoice Where (InHomeDate BETWEEN @Date1 and @Date2)"; using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.Add(new SqlParameter("@Date1", SqlDbType.DateTime)).Value = DateTime.Today.AddDays(-180); cmd.Parameters.Add(new SqlParameter("@Date2", SqlDbType.DateTime)).Value = DateTime.Today; using (SqlDataReader dr = cmd.ExecuteReader()) { DataTable dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; } } } }
•
•
Join Date: Oct 2009
Posts: 14
Reputation:
Solved Threads: 0
0
#13 Oct 22nd, 2009
•
•
•
•
Oh, try something like this:
C# Syntax (Toggle Plain Text)
private void button2_Click(object sender, EventArgs e) { const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;"; const string query = "Select * From Invoice Where (InHomeDate BETWEEN @Date1 and @Date2)"; using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.Add(new SqlParameter("@Date1", SqlDbType.DateTime)).Value = DateTime.Today.AddDays(-180); cmd.Parameters.Add(new SqlParameter("@Date2", SqlDbType.DateTime)).Value = DateTime.Today; using (SqlDataReader dr = cmd.ExecuteReader()) { DataTable dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; } } } }
•
•
Join Date: Oct 2009
Posts: 14
Reputation:
Solved Threads: 0
0
#14 Oct 22nd, 2009
the code was
for each one @date
C# Syntax (Toggle Plain Text)
mySqlCommand.Parameters.Add(new SqlParameter("@date1", SqlDbType.DateTime)); mySqlCommand.Parameters["@date1"].Value = dateTimePicker1.Value;
![]() |
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: 674 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast button buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development drawing encryption enum event excel file files form format ftp function gcd gdi+ http httpwebrequest image index input java list listbox listener login mandelbrot math mouseclick mysql networking object oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view webbrowser windows winforms wpf xml






