Problème pour numéro automatique

Résolu
dinier Messages postés 12 Date d'inscription dimanche 15 août 2010 Statut Membre Dernière intervention 13 septembre 2010 - 25 mai 2009 à 18:20
dinier Messages postés 12 Date d'inscription dimanche 15 août 2010 Statut Membre Dernière intervention 13 septembre 2010 - 26 mai 2009 à 13:58
Bonjour à tous,
J'ai un problème avec un numéro automatique, j'ai fait un dataset, et lorsque j'ai effacé par exemple les numéros 1, 2, 3 et qu'il ny a plus rien dans la base, je relance le programme, et je clique sur ajouter, et là j'ai de nouveau 1, 2, 3 dans le formulaire et dans la base, j'ai 4, 5, 6. Comment faire pour régler ce problème.
Voici le code du bouton ajout :
private void bt_ajout_serv_Click(object sender, EventArgs e)
{
this.BindingContext[dbDs, dbDs.tp1_service.TableName].AddNew();
fillData();
}

private void fillData()
{
string total = (this.BindingContext[dbDs, "tp1_service.serviceemploye"].Count).ToString();
string num = ((this.BindingContext[dbDs, "tp1_service.serviceemploye"].Position) + 1).ToString();
tb_posCpt_emp.Text = num + "/" + total;

total = (this.BindingContext[dbDs, dbDs.tp1_service.TableName].Count).ToString();
num = ((this.BindingContext[dbDs, dbDs.tp1_service.TableName].Position) + 1).ToString();
tb_posCpt_serv.Text = num + "/" + total;

try
{
activeService = this.BindingContext[dbDs, dbDs.tp1_employe.TableName].Current as DataRowView;
rowView = this.BindingContext[dbDs, "tp1_service.serviceemploye"].Current as DataRowView;
}
catch {}
if (rowView != null)
{
if ((bool)rowView.Row["sexe"] == true)
this.rb_masculin.Checked = true;
else
this.rb_feminin.Checked = true;
}
else
{
this.cb_service.SelectedValue = false;
}
}
Merci à vous

2 réponses

dinier Messages postés 12 Date d'inscription dimanche 15 août 2010 Statut Membre Dernière intervention 13 septembre 2010
25 mai 2009 à 18:23
Désolé, je renvoie le code car c'est illisible.
privatevoid bt_ajout_serv_Click(object sender, EventArgs e)
        {
            this.BindingContext[dbDs, dbDs.tp1_service.TableName].AddNew();
            fillData();
        }
 
privatevoid fillData()
        {
            string total = (this.BindingContext[dbDs, "tp1_service.serviceemploye"].Count).ToString();
            string num = ((this.BindingContext[dbDs, "tp1_service.serviceemploye"].Position) + 1).ToString();
            tb_posCpt_emp.Text = num + "/" + total;
 
            total = (this.BindingContext[dbDs, dbDs.tp1_service.TableName].Count).ToString();
            num = ((this.BindingContext[dbDs, dbDs.tp1_service.TableName].Position) + 1).ToString();
            tb_posCpt_serv.Text = num + "/" + total;
           
            try
            {
                activeService = this.BindingContext[dbDs, dbDs.tp1_employe.TableName].Currentas DataRowView;
                rowView = this.BindingContext[dbDs, "tp1_service.serviceemploye"].Currentas DataRowView;
            }
            catch{}
            if(rowView != null)
            {
                if((bool)rowView.Row["sexe"] == true)
                    this.rb_masculin.Checked = true;
                else
                    this.rb_feminin.Checked = true;
            }
            else
            {
                this.cb_service.SelectedValue = false;
            }
        }
3
dinier Messages postés 12 Date d'inscription dimanche 15 août 2010 Statut Membre Dernière intervention 13 septembre 2010
26 mai 2009 à 13:58
Je pense que je pourrai rafraichir le dataset juste pour la valeur du textbox mais comment faire car j'ai essayé avec rafraichir le dataset lorsque je fais un sqldataadapter mais cela me met un message d'erreur de double connexion.
3
Rejoignez-nous