private int GetNextId()
{
SQLiteConnector conn = new SQLiteConnector(false);
conn.OpenConnection();
cmd = new SQLiteCommand("SELECT @id_account = MAX(id_account) FROM account");
SQLiteParameter param = new SQLiteParameter("@id_account", DbType.Int32);
param.Direction = ParameterDirection.Output;
cmd.Parameters.Add(param);
cmd = conn.ExecuteReadeOutput(cmd);
conn.Close();
return int.Parse(cmd.Parameters["id_account"].Value.ToString()) + 1;
}
...
public SQLiteCommand ExecuteReadeOutput(SQLiteCommand cmd)
{
conn.Open();
cmd.Connection = conn;
reader = cmd.ExecuteReader();
reader.Close();
return cmd;
}
当我调用方法GetNextId()
时,会出现以下错误:
指定的参数超出了有效值的范围。
在线:
param.Direction = ParameterDirection.Output;
有什么想法吗?
感谢。
答案 0 :(得分:0)
对你的问题不是一个直接的答案,但如果你只写:
SELECT MAX(id_account) FROM account
然后通过普通的DataReader
,您可以检索唯一值。在这种情况下,不需要声明任何参数。
卢西恩