May be this is the reason insertion is failing,you are casting the result of ExcecuteNonQuery()
int i = (int)cmd.ExecuteNonQuery();
ExecuteNonQuery() returns integer so no need to cast it
Or the other reason may be your primary key is not autoincrement and should be given in insert statement