SQLite具有与MySQL不同的选择查询。我怎样才能解决这个问题?

时间:2017-04-24 10:05:52

标签: c# mysql .net winforms sqlite

将值导入SQLite后,我尝试通过选择查询来提取一个图形的值,但是我收到以下错误:

  

SQL逻辑错误或缺少数据库
  没有这样的功能:年

这是我的插入查询:

string addDat = "";

if (splittedValues[3] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-01-" + (int.Parse(splittedValues[2])<10?"0":"") + splittedValues[2] + "', " + splittedValues[3] + ");";
}

if (splittedValues[4] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-02-" + splittedValues[2] + "', " + splittedValues[4] + ");";
}

if (splittedValues[5] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-03-" + splittedValues[2] + "', " + splittedValues[5] + ");";
}

if (splittedValues[6] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-04-" + splittedValues[2] + "', " + splittedValues[6] + ");";
}

if (splittedValues[7] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-05-" + splittedValues[2] + "', " + splittedValues[7] + ");";
}

if (splittedValues[8] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-06-" + splittedValues[2] + "', " + splittedValues[8] + ");";
}

if (splittedValues[9] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-07-" + splittedValues[2] + "', " + splittedValues[9] + ");";
}

if (splittedValues[10] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-08-" + splittedValues[2] + "', " + splittedValues[10] + ");";
}

if (splittedValues[11] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-09-" + splittedValues[2] + "', " + splittedValues[11] + ");";
}

if (splittedValues[12] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-10-" + splittedValues[2] + "', " + splittedValues[12] + ");";
}

if (splittedValues[13] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-11-" + splittedValues[2] + "', " + splittedValues[13] + ");";
}

if (splittedValues[14] != "")
{
    addDat += "INSERT INTO hyddnev (Station, Dat, Vkol) values (" + resultStation + ", '" + splittedValues[1] + "-12-" + splittedValues[2] + "', " + splittedValues[14] + ");";
}

使用splittedValues[1]我插入年份,从01到12是月,splittedValues[2]是几天。

现在我想从SQLite获取值:

private void loadButton_Click(object sender, EventArgs e)
{
    string command4 = "select vkol from hyddnev where station='"
        + comboBox1.SelectedItem.ToString() + "' and year(Dat) = '"
        + comboBox2.SelectedItem.ToString() + "' order by Dat";

    var StartDate = comboBox2.Text;
    var EndDate = comboBox2.Text;

    SQLiteCommand sqlComm;
    sqlComm = new SQLiteCommand("begin", Connection);
    sqlComm.ExecuteNonQuery();

    SQLiteDataAdapter insertDat = new SQLiteDataAdapter(command4, Connection);
    DataTable dt = new DataTable();
    insertDat.Fill(dt);

    string s2 = "";
    int i = 0;

    int startYear2 = 0;
    int.TryParse(StartDate, out startYear2);
    DateTime dtStart2 = new DateTime(startYear2, 01, 01);
    chart1.Series["Avg"].XValueType = ChartValueType.DateTime;
    chart1.ChartAreas[0].AxisX.LabelStyle.Format = "yyyy-MM-dd";
    chart1.ChartAreas[0].AxisX.Interval = 1;
    chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;
    chart1.ChartAreas[0].AxisX.IntervalOffset = 1;

    chart1.Series["Avg"].MarkerSize = 10;

    foreach (DataRow row in dt.Rows)
    {
        chart1.Series["Avg"].Points.AddXY(dtStart2.AddDays(i), row.ItemArray[0]);
        i++;

        string rowz = string.Format("Avg Q - {0}" + Environment.NewLine, row.ItemArray[0]);
        s2 += "" + rowz;
    }

如何修复此代码?我认为我的问题来自选择查询?

我可以举一些例子来获得一年吗?因为在combobox2中我只选择年份,我没有几个月和几天......

谢谢..

0 个答案:

没有答案