Ilya
Ilya

Reputation: 13

Insufficient parameters supplied for to the command INSERT in SQLite

I am trying to connect my program to a SQLite DB, I want it to add a row in the DB each time a user logs in, I am using Dapper ORM.

I have already checked the names of the databse rows and the User class parameters, I have tried to send both obj and uUser as parameters. I have also tried to write a simple test application and the same command works there.

public class User
    {
        // Parameter def
        public string stClass;
        public string stUsername;
        public string LoginDate;
        private string stPassword;
    }

    // Saves the user to the DB
    public static void SaveData(Object obj, string stpTableName)
    {
        // First case (Irrelevant)

        case(USERS):
        {
            User uUser = new User();
            uUser = (User)obj;

            // Opens and closes the connection to the DB
            using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
            {
                cnn.Execute("insert into Users (stUsername, stClass, LoginDate) values (@stUsername, @stClass, @LoginDate)", uUser);
            }
        }

    }

The program fails on cnn.Execute with Insufficient Parameters supplied error.

Upvotes: 1

Views: 155

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062875

Dapper loves properties. Try:

public class User
{
    // Parameter def
    public string Class {get;set;}
    public string Username {get;set;}
    public DateTime LoginDate {get;set;}
    private string Password {get;set;} // mutters something about "salted hashes"
}
...
cnn.Execute("insert into Users (stUsername, stClass, LoginDate) values (@Username, @Class, @LoginDate)", uUser);

(you don't have to change the names... but I just can't type public string stClass {get;set;} without wincing)

Upvotes: 1

Related Questions