C# .NET - WIthout using db can we store values in local variables in winforms

Asked By kavitha varma on 14-May-12 03:27 AM
Hai
         can we store the values of username ,register name ,password like this in local variables with out db.
Suchit shah replied to kavitha varma on 14-May-12 03:32 AM

In winforms you can use variables that are exposed to other forms through methods or properties.

You can also use static variables.

Jitendra Faye replied to kavitha varma on 14-May-12 04:40 AM
If you don't want to use DataBase then  you can use create one class like this-

class data
{
   public string username {get;set}
   public string registername{get;set};
   public string password {get;set};

}

Now create object for this class-


data obj= new obj();
obj.username="value1";
obj.registername="value2";
obj.password ="value3";


this is only for front end.
kavitha varma replied to Jitendra Faye on 14-May-12 04:47 AM
then how can i store the values
vijaya saladi replied to kavitha varma on 14-May-12 04:56 AM
Try to solve it using delegates yar.\
Like

public partial class frmID : Form
    {

      // add a delegate
      public delegate void IdentityUpdateHandler(object sender, IdentityUpdateEventArgs e);

      // add an event of the delegate type
      public event IdentityUpdateHandler IdentityUpdated;
     
     

      // default constructor
      public frmID()
      {
        InitializeComponent();
      }

      // close the form without raising the event
      private void btnCancel_Click(object sender, EventArgs e)
      {
        this.Dispose();
      }

      // raise the event
      private void btnOkay_Click(object sender, EventArgs e)
      {
        // this button click event handler will raise the
        // event which can then intercepted by any listeners

        // read the textboxes and set the member variables
        string sNewFirst = txtFirstName.Text;
        string sNewMiddle = txtMiddleName.Text;
        string sNewLast = txtLastName.Text;

        // instance the event args and pass it each value
       
        IdentityUpdateEventArgs args = new IdentityUpdateEventArgs(sNewFirst,
          sNewMiddle, sNewLast);
       

        // raise the event with the updated arguments
        IdentityUpdated(this, args);

        this.Dispose();
      }
    }

    public class IdentityUpdateEventArgs : System.EventArgs
    {
      // add local member variable to hold text
      private string mFirstName;
      private string mMiddleName;
      private string mLastName;

      // class constructor
      public IdentityUpdateEventArgs(string sFirstName, string sMiddleName, string sLastName)
      {


        this.mFirstName = sFirstName;
        this.mMiddleName = sMiddleName;
        this.mLastName = sLastName;
      }

      // Properties - Accessible by the listener

      public string FirstName
      {
        get
        {
          return mFirstName;
        }
      }

      public string MiddleName
      {
        get
        {
          return mMiddleName;
        }
      }

      public string LastName
      {
        get
        {
          return mLastName;
        }
      }
    }


all the best
Jitendra Faye replied to kavitha varma on 14-May-12 05:01 AM
Where you want to store the value, if you don't want to use DataBase then you can store value in XML file also.

you can serialize this class object to Xml file using XmlSerialization.