-1
我有錯誤,我希望做一個過濾器,它由一些組合框和的DateTimePicker和它的將是展現在dategridview。而當我想選擇DATEBASE日期,我有這樣的錯誤:MS Access數據類型不匹配C#
"Data type mismatch in criteria expression".
string strSql1 = @"Select * from GGG where
device_id LIKE '%" + metroComboBox1.Text + "%'
AND parameter_id LIKE '%" + metroComboBox3.Text + "%'
AND time_id Between 'date1' AND 'date2'";`
string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Ирина\\Desktop\\Visual Studio 2013\\Projects\\WindowsFormsApplication1\\WindowsFormsApplication1\\BD3.accdb;Persist Security Info=False";
string date1 = metroDateTime1.Value.ToString("MM/dd/yyyy H:mm:ss", CultureInfo.InvariantCulture).Replace('.', '/');
string date2 = metroDateTime3.Value.ToString("MM/dd/yyyy H:mm:ss", CultureInfo.InvariantCulture).Replace('.', '/');
//string strSql = ("SELECT * FROM GGG where device_id LIKE '%" + metroComboBox1.Text + "%' AND parameter_id LIKE '%" + metroComboBox3.Text + "%' ");
string strSql1 = "Select * from table1 where device_id LIKE '%" + metroComboBox1.Text + "%' AND parameter_id LIKE '%" + metroComboBox3.Text + "%' AND time_id Between 'date1' AND 'date2'";
//string strSql = "SELECT event_id, device_id, parameter_id, parameter_int_id, time_id, user_id FROM table1 where time_id between #" + metroDateTime1.Value.ToString("yyyy'/'MM'/'dd") + "# AND #" + metroDateTime3.Value.ToString("yyyy'/'MM'/'dd") + "" "# AND #" device_id LIKE '%" + comboBox2.Text + "%' "# AND #" parameter_id LIKE '%" + comboBox3.Text + "%' ");
//string strSql = "SELECT event_id, device_id, parameter_id, date_id, time_id, user_id FROM GGG where device_id like '%" + metroComboBox1.Text + "%' AND parameter_id LIKE '%" + metroComboBox3.Text + "%' ";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand cmd = new OleDbCommand(strSql1, con);
con.Open();
cmd.CommandType = CommandType.Text;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable GGG = new DataTable();
da.Fill(GGG);
metroGrid1.DataSource = GGG;
con.Close();
不行,同樣的錯誤 –
但我連接的OleDbCommand(MS接入),不是SQL –
對不起 - 習慣。我改變了我的答案 –