Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trying to 'Add' a record to a dataset
Message
De
13/12/2004 09:37:02
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00968525
Message ID:
00968722
Vues:
8
You're welcome, Gerard!

~~Bonnie


>Hi Bonnie.
>That certainly did the trick for adding the record.. I'll play around with the rest.
>
>Thanks again for your assistance.
>
>Regards,
>
>Gerard
>
>
>>Gerard,
>>
>>>>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 ??<
>>
>>Nah, that's not it. I'm thinking that it's probably your BindingContext. There are two different ways to specify this and .NET thinks they are two different BindingManagers, even though you're binding to the same table.
>>
>>I told you to do it this way:
>>
>>            this.BindingContext[this.dsIFSR.Tables["IFISR"]].Position = recno ;
>>
>>But, you could also do it this way:
>>
>>            this.BindingContext[this.dsIFSR, "IFISR"].Position = recno ;
>>
>>See the difference? Same table, but different BindingManager objects. Try it the second way and see if that does it for you.
>>
>>~~Bonnie
>>
>>
>>
>>>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
Bonnie Berent DeWitt
NET/C# MVP since 2003

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

Click here to load this message in the networking platform