Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# - Add and Update Records
Message
De
08/04/2008 19:11:49
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01309187
Message ID:
01309197
Vues:
12
Kevin,

You can just overload the constructor for the user form
Create a variable in the form
private int UserId = -1;

// constructor for the form with no id passed in
public frmUser()
{

}

// Constructor for the form with a userid passed in
public frmUser(int userId)
{
   this.UserId = userId;
}

public frmUser_Load(object sender, EventArgs e)
{
   if (this.UserId > -1)
   {
      // We are editing, so get call a function to get the data and bind it to the controls.
   } 
}

Now to use this from somewhere else all you need to do is initialize the form.
frmUser oUser = new frmUser();

or if you want to edit
frmUser oUser = new frmUser(id);
frmUser.ShowDialog();
>Next newby question.
>
>I want to create a basic data entry form. In past VFP applications I accepted the PK of the record in the Init of
>the form. If the PK was passed, I loaded the record and entered Edit Mode. If no PK was passed, I assumed Add Mode.
>I don't see why I cannot do the same in my C# app:
>
>
>frmUser oUser = new frmUser();
>
>// If creating a new user...
>oUser.SetupForm();
>
>// If opening an existing user...
>oUser.SetupForm(iUserKey);
>
>oUser.ShowDialog();
>
>
>I'm open to other ideas on this.
>
>Next, when I am going into Add Mode, do I first create a data set, then add a row? Or is there some other way.
>An example would be helpful.

Yes, that is what I would do as your controls could be bound to the dataset already. If you are adding, then just add a new row and make it the current row.

I hope that helps
Tim
Timothy Bryan
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform