Access 2016, VS 2017, C #
Error System.Data.OleDb.OleDbException: "Data type mismatch in the selection condition expression." Swears on OleDbDataReader tarif = cmd.ExecuteReader ();
It is necessary to display the amount of revenue for a certain period by the request, on the form 2 datetimepicker, textbox and button Please help.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form13 : Form { public Form13() { InitializeComponent(); } private void Form13_FormClosed(object sender, FormClosedEventArgs e) { Form3 form3 = new Form3(); this.Visible = false; form3.ShowDialog(); this.Close(); } private void button1_Click(object sender, EventArgs e) { string str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Museum.mdb"; OleDbConnection cn = new OleDbConnection(str); OleDbCommand cmd = new OleDbCommand("Select sum(Сумма) as Итого from Экскурсии where [Дата] between '"+ DateTime.Parse(string.Format("{0:yyyy-MM-dd}", dateTimePicker1.Value)) + "' and '"+ DateTime.Parse(string.Format("{0:yyyy-MM-dd}", dateTimePicker1.Value)) + "'" , cn); cn.Open(); OleDbDataReader tarif = cmd.ExecuteReader(); while (tarif.Read()) { textBox1.Text = Convert.ToString(tarif["Итого"]); } textBox1.TabStop = false; } } }