开发者

Finisar SQLite Problem with ParameterDirection

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;
}

When I call the method GetNextId() occur the following error:

Specified argument was out of t开发者_如何学编程he range of valid values.

at line:

param.Direction = ParameterDirection.Output;

Any idea?

Thanks.


Not quite a direct answer to your question, but what if you write just:

SELECT MAX(id_account) FROM account

then through an ordinary DataReader you can retrieve the unique value. In this case, there is no need to declare any parameter.

Lucian

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜