Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trying to 'Add' a record to a dataset
Message
De
11/12/2004 10:26:24
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00968525
Message ID:
00968533
Vues:
8
Gerard,

Yeah, it's a bit confusing at times, isn't it? <s>

The NewRow() method doesn't actually add the new row to the DataSet. Here's how you have to do it:
DataRow row = this.ds.Tables["MYTABLE"].NewRow();
// if you needed to initialize any columns:
row["MyFirstColumn"] = "whatever";
this.ds.Tables["MYTABLE"].Rows.Add(row);
Also, since you said that you need to "go" to that row, you'll need to update the BindingContext Position, like this:
int recno = this.ds.Tables["MYTABLE"].Rows.Count - 1;
this.BindingContext[this.ds.Tables["MYTABLE"]].Position = recno;
That should do it!

~~Bonnie



>Hi.
>I have a form with two pages, Grid in page one and Controls in Page 2
>I have a Dataset displaying fine in page one, with controls in Page Two.
>
>I have an 'Add' button , the purpose of which is to 'Add' a new record
>I have following code in click event:
>this.ds.Tables["MYTABLE"].NewRow();
>
>This seems to run (.i.e does not give an error message) but I cannot see a new record in the Grid ?
>
>What I would like to do is:
>1. Add the new record to the Dataset Table
>2. 'Land' on this record (i.e. Goto MyNewDatSetRecord)
>3. Set focus to the first field on Page 2
>
>Any assistance greatly appeciated
>
>Regards
>Gerard
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform