我的最终结果是来自数据库的数据将填充datagridview。
现在,我限制自己只能调用31个数据,仅此而已。我也有一些错误,例如从日期中调出数据。但是我可以根据零件号调出,但是我想我已经将girdview上的行设置为31,这就是为什么它只能调出31个数据的原因
我尝试了google并更改了日期调用的格式,但是它不起作用
SQLiteConnection con = new SQLiteConnection("Data Source=|DataDirectory|\\trendchart.db");
con.Open();
int i = 0;
SQLiteCommand Insert = new SQLiteCommand("Select * from d where dateandtime = '" + dateTimePicker1.Value.ToString("dd-MM-yyyy") + "' and Date= '" + dateTimePicker2.Value.AddDays(0).ToString("dd-MM-yyyy") , con);
SQLiteDataReader dr1 = Insert.ExecuteReader();
dataGridView2.Rows.Clear();
dataGridView2.DataSource = null;
dataGridView2.Refresh();
this.dataGridView2.Rows.Add();
this.dataGridView2.Rows.Add();
this.dataGridView2.Rows.Add();
this.dataGridView2.Rows.Add();
this.dataGridView2.Rows.Add();
this.dataGridView2.Rows.Add();
this.dataGridView2.Rows.Add();
this.dataGridView2.Rows.Add();
this.dataGridView2.Rows.Add();
this.dataGridView2.Rows.Add();
this.dataGridView2.Rows.Add();
this.dataGridView2.Rows.Add();
dataGridView2.Rows[0].HeaderCell.Value = "Date";
dataGridView2.Rows[1].HeaderCell.Value = "Day (D) / Night (N)";
dataGridView2.Rows[2].HeaderCell.Value = "TOP(1)";
dataGridView2.Rows[3].HeaderCell.Value = "TOP(2)";
dataGridView2.Rows[4].HeaderCell.Value = "Bottom(1)";
dataGridView2.Rows[5].HeaderCell.Value = "Bottom(2)";
dataGridView2.Rows[6].HeaderCell.Value = "X-TOP";
dataGridView2.Rows[7].HeaderCell.Value = "X-BOT";
dataGridView2.Rows[8].HeaderCell.Value = "X-T/B";
dataGridView2.Rows[9].HeaderCell.Value = "Range";
dataGridView2.Rows[10].HeaderCell.Value = "Employee no";
dataGridView2.Rows[11].HeaderCell.Value = "Date&time";
for (int r = 0; r < 31; r++)
{
dataGridView2.Rows[0].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[1].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[2].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[3].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[4].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[5].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[6].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[7].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[8].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[9].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[10].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[11].Cells[r].Style.Font = new Font("Arial", 11, FontStyle.Regular);
dataGridView2.Rows[6].Cells[r].Style.BackColor = Color.Gray;
dataGridView2.Rows[7].Cells[r].Style.BackColor = Color.Gray;
dataGridView2.Rows[8].Cells[r].Style.BackColor = Color.Gray;
dataGridView2.Rows[9].Cells[r].Style.BackColor = Color.Gray;
dataGridView2.Rows[10].Cells[r].Style.BackColor = Color.Gray;
dataGridView2.Rows[11].Cells[r].Style.BackColor = Color.Gray;
}
while (dr1.Read())
{
string f1 = dr1.GetString(0);
string f2 = dr1.GetString(1);
string f3 = dr1.GetString(2);
string f4 = dr1.GetString(3);
string f5 = dr1.GetString(4);
string f6 = dr1.GetString(5);
string f7 = dr1.GetString(6);
string f8 = dr1.GetString(7);
string f9 = dr1.GetString(8);
string f10 = dr1.GetString(9);
string f11 = dr1.GetString(10);
string f12 = dr1.GetString(11);
dataGridView2.Rows[0].Cells[i].Value = f1;
dataGridView2.Rows[1].Cells[i].Value = f2;
dataGridView2.Rows[2].Cells[i].Value = f3;
dataGridView2.Rows[3].Cells[i].Value = f4;
dataGridView2.Rows[4].Cells[i].Value = f5;
dataGridView2.Rows[5].Cells[i].Value = f6;
dataGridView2.Rows[6].Cells[i].Value = f7;
dataGridView2.Rows[7].Cells[i].Value = f8;
dataGridView2.Rows[8].Cells[i].Value = f9;
dataGridView2.Rows[9].Cells[i].Value = f10;
dataGridView2.Rows[10].Cells[i].Value = f11;
dataGridView2.Rows[11].Cells[i].Value = f12;
i++;
}
“代码=错误(1),消息= System.Data.SQLite.SQLiteException(0x800007BF):SQL逻辑错误 无法识别的令牌:“'29-12-2018””
答案 0 :(得分:0)
缺少引号,将其添加为:
SQLiteCommand Insert = new SQLiteCommand("Select * from d where dateandtime = '" + dateTimePicker1.Value.ToString("dd-MM-yyyy") + "' and Date= '" + dateTimePicker2.Value.ToString("dd-MM-yyyy") + "'" , con);