G
Guest
I have a gui build from a dataset. The gui consists of an ID field (identy
and key field in the database) and a name field.
I have a textfile with only the names in it. I want to fill the database
with the names from the textfile. The ID's have to be generated by the
database.
My first try was:
//The textfile is read into an arraylist al...
if (al.Count > 0)
{
filmsBindingSource.AllowNew = true;
foreach (string[] s in al)
{
filmsBindingSource.AddNew();
nameTextBox.Text = s[0].Trim();
}
}
After that the gui is updated and shows the inserted records. A push on the
save button in the bindingsourcenavigator should do the trick. But than it
complains about the identity field in the database: exeption, 'column FilmID
is constrained to be unique. Value '5' already exists'. The database is
however empty (I experimented with the database, but deleted all records).
Next try was through inserting records in the dataset:
//The textfile is read into an arraylist al...
if (al.Count > 0)
{
foreach (string[] s in al)
{
newFilmRow = filmsDBDataSet.Tables["Films"].NewRow();
newFilmRow["Titel"] = s[0].Trim();
filmsDBDataSet.Tables["Films"].Rows.Add(newFilmRow);
}
}
After this I see the records in de gui. A save from the
bindingsourcenavigator leads to the same exeption.
Questions are:
- how do I fill the dataset / bindingsource?
- how do I handle the identity field? After the fills shown above, the
identity field in the gui starts with 0 but this should be 1.
- What is the relation between the gui identity field and the database
identy field?
- What method should I use to fill the records?
Thnaks in advance,
Eric Algera (NL)
and key field in the database) and a name field.
I have a textfile with only the names in it. I want to fill the database
with the names from the textfile. The ID's have to be generated by the
database.
My first try was:
//The textfile is read into an arraylist al...
if (al.Count > 0)
{
filmsBindingSource.AllowNew = true;
foreach (string[] s in al)
{
filmsBindingSource.AddNew();
nameTextBox.Text = s[0].Trim();
}
}
After that the gui is updated and shows the inserted records. A push on the
save button in the bindingsourcenavigator should do the trick. But than it
complains about the identity field in the database: exeption, 'column FilmID
is constrained to be unique. Value '5' already exists'. The database is
however empty (I experimented with the database, but deleted all records).
Next try was through inserting records in the dataset:
//The textfile is read into an arraylist al...
if (al.Count > 0)
{
foreach (string[] s in al)
{
newFilmRow = filmsDBDataSet.Tables["Films"].NewRow();
newFilmRow["Titel"] = s[0].Trim();
filmsDBDataSet.Tables["Films"].Rows.Add(newFilmRow);
}
}
After this I see the records in de gui. A save from the
bindingsourcenavigator leads to the same exeption.
Questions are:
- how do I fill the dataset / bindingsource?
- how do I handle the identity field? After the fills shown above, the
identity field in the gui starts with 0 but this should be 1.
- What is the relation between the gui identity field and the database
identy field?
- What method should I use to fill the records?
Thnaks in advance,
Eric Algera (NL)