I am trying to use SQLite in WinForms. So I created a table named Artist
and it has 2 columns named ArtistId
, Name
. ArtistId's properties are: INTEGER
PRIMARY
AUTOINCREMENT
.
In the foreach loop, if I give manually value, there is no problem.
LtoSQLiteDataContext oc = new LtoSQLiteDataContext();
int i = 1;
foreach (var pdfs in articles)
{
var r = new PdfReader(pdfs);
var title = r.Info["Title"].Trim();
var m = new Artist
{
ArtistId = i,
Name = title
};
oc.Artists.InsertOnSubmit(m);
oc.SubmitChanges();
i++;
}
But if I ignore ArtistId like //ArtistId = i;
, in the first record, ArtistId
gets 0
and process is terminated. Here is screenshot:
I know in MySQL and MsSQL, auto increment field's value is never written. Because it gets number in the sequence. I don't know, how auto increment poperty works correctly.
Aucun commentaire:
Enregistrer un commentaire