Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trying to 'Add' a record to a dataset
Message
 
À
12/12/2004 10:39:15
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00968525
Message ID:
00968639
Vues:
8
Hi Bonnie:
Code in Click of 'Add' Button:-

DataRow dr = this.dsIFSR.Tables["IFISR"].NewRow();
// dr["MyFirstColumn"] = "whatever";
this.dsIFSR.Tables["IFISR"].Rows.Add(dr);

// Go to the new row
int recno = this.dsIFSR.Tables["IFISR"].Rows.Count - 1;
this.BindingContext[this.dsIFSR.Tables["IFISR"]].Position = recno ;

I just noticed now that the only bit I left out was the MyFirstColumn bit... I wonder if this is causing it.... maybe this sets focus ??

Regards,
Gerard




>Gerard,
>
>Hmmm ... that *should* work. Can you post the relevant part of your code?
>
>~~Bonnie
>
>
>
>>Hi Bonnie.
>>
>>Thats worked fine for 'Adding' the record, as I can see that a new blank record is added ok.
>>The record pointer in the Grid stays on the record it was originally positioned though.
>>
>>(The Grid is read only... but I woul'nt have thought that should matter ?)
>>
>>
>>>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform