Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C-SQLite更新查询工作不正常_C#_Sqlite - Fatal编程技术网

C# C-SQLite更新查询工作不正常

C# C-SQLite更新查询工作不正常,c#,sqlite,C#,Sqlite,我将在开始这个问题时说,我知道这不是使用SQLite语句的最佳方式,但在学习时对我来说更容易。以下是我的部分代码: int horas1, minutos1, segundos1, horas2, minutos2, segundos2; pausaString = "No"; TimeSpan ts = turriStopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.

我将在开始这个问题时说,我知道这不是使用SQLite语句的最佳方式,但在学习时对我来说更容易。以下是我的部分代码:

int horas1, minutos1, segundos1, horas2, minutos2, segundos2;
pausaString = "No";
TimeSpan ts = turriStopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds);
MessageBox.Show(elapsedTime, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
string sql = "select tiempoPausado from Registros where pausado = 'SI' and enCurso = 'SI' and operacion = '" + operacionString + "' and operador = '" + operadorString + "'";
command = new SQLiteCommand(sql, conexion);
using (SQLiteDataReader reader2 = command.ExecuteReader())
   {
      if (reader2.Read())
      {
         string tiempoGuardado = reader2.GetString(0);

         horas1 = Convert.ToInt16(tiempoGuardado.Substring(0, 2));
         minutos1 = Convert.ToInt16(tiempoGuardado.Substring(3, 2));
         segundos1 = Convert.ToInt16(tiempoGuardado.Substring(6, 2));

         horas2 = Convert.ToInt16(elapsedTime.Substring(0, 2));
         minutos2 = Convert.ToInt16(elapsedTime.Substring(3, 2));
         segundos2 = Convert.ToInt16(elapsedTime.Substring(6, 2));
         //MessageBox.Show(horas2 + ";" + minutos2 + ";" + segundos2, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

         int sumaHoras = horas1 + horas2;
         int sumaMinutos = minutos1 + minutos2;
         int sumaSegundos = segundos1 + segundos2;

         while (sumaSegundos >= 60) 
         {
            sumaMinutos = sumaMinutos + 1;
            sumaSegundos = sumaSegundos - 60;
         }
         while (sumaMinutos >= 60) 
         {
            sumaHoras = sumaHoras + 1;
            sumaMinutos = sumaMinutos - 60;
         }

         string horarioAGuardar = String.Format("{0:00}:{1:00}:{2:00}", sumaHoras, sumaMinutos, sumaSegundos);

         //MessageBox.Show(horarioAGuardar, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

         sql = "update Registros set tiempoPausado = '" + horarioAGuardar + "' AND pausado = 'NO' where enCurso = 'SI' AND operador = '" + operadorString + "' AND operacion = '" + operacionString + "'";
         command = new SQLiteCommand(sql, conexion);
         int rows = command.ExecuteNonQuery();
         MessageBox.Show(rows.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }

      else
      {

      }

}
小时计算工作正常,但假设tiempoAGuardar是00:00:02,我从数据库中得到的tiempoPausado是0,pausado没有更改为“否”。即使我使用asd更改TiemPaguarDar,它也会在数据库中存储0。请帮忙,我已经想了好几天了。谢谢,UPDATE语句的语法错误

你有这个:

"update Registros set tiempoPausado = '" + horarioAGuardar + "' AND pausado = 'NO'
您需要将和替换为逗号:

"update Registros set tiempoPausado = '" + horarioAGuardar + "', pausado = 'NO'

很可能AND pausado='NO'被解析为表达式的一部分,该表达式将被计算以形成TIEMPOUSADO的最终值。

update语句的语法似乎不正确,您可以:update x SET a=b,k=l not:update x SET a=b和k=l,请注意,我在要更新的两列之间使用了逗号和not。你能确认没有例外吗?你有没有我们没有看到的尝试/发现?谢谢@LasseV.Karlsen!!!当我用逗号改变时,它就起作用了。我不明白为什么,但现在它起作用了。非常感谢。很可能它被解析为一个表达式,pausado='NO'检查pausado,并根据它计算为true或false,然后与要存储到第一个字段中的值一起进行AND运算。简言之,你有这样一个:et tiempousado='+horarioAGuardar+'和pausado='NO',虽然这只是一个猜测,我不知道它是如何解析的,但很好,它工作了。