hello guys i would like to make a form where a users can input answers to some questions
example.............
name, age ,address , tel number , time , date and so on
(and users input the information in a provided field(textbox)
and i want my users data to be stored so that i can use it to obtain organized information out of it. which is the best way to do this ?
thanks
Loading
azzo stonesPosted Aug 13, 2011, 3:59 PM
Sam HobbsPosted Aug 12, 2011, 7:54 PM
For what you are asking, the best solution might be to store the data as properties. Would there be only one set of data ("name, age ,address , tel number , time , date and so on") per Windows user? If so, then you could use properties, and then the data will be saved in a special XML file and the programming will be very easy.
For the household water and electric consumption, it will be better if you continue with your thread Electric and water usage program.
azzo stonesPosted Aug 12, 2011, 5:50 PM
azzo stonesPosted Aug 12, 2011, 5:48 PM
VulpesPosted Aug 12, 2011, 5:41 PM
You can then assign its properties to the appropriate textboxes.
azzo stonesPosted Aug 12, 2011, 5:17 PM
VulpesPosted Aug 12, 2011, 2:17 PM
For example:
using System.IO;
using System.Xml;
using System.Xml.Serialization;
public class User
{
public string Name {get; set;}
public int Age {get; set;}
public string TelNo {get; set;}
public DateTime Date {get; set;}
public User()
{
}
public User(string name, int age, string telNo, DateTime date)
{
Name = name;
Age = age;
TelNo = telNo;
Date = date;
}
public override string ToString()
{
return String.Format("{0}, {1}, {2}, {3}", Name, Age, TelNo, Date.ToString("MM/dd/yyyy"));
}
}
// code to serialize to disk
User u = new User(txtName.Text, int.Parse(txtAge.Text), txtTelNo.Text, DateTime.Parse(txtDate.Text);
XmlSerializer xs = new XmlSerializer(typeof(User));
using(Stream s = File.Create("user.xml"))
{
xs.Serialize(s, u);
}
// code to deserialize from disk
User u2;
using(Stream s = File.OpenRead("user.xml"))
{
u2 = (User)xs.Deserialize(s);
}
txtName.Text = u2.Name;
txtAge.Text = u2.Age.ToString();
txtTelNo.Text = u2.TelNo;
txtDate.Text = u2.Date.ToString("MM/dd/yyyy");
// or display in a MessageBox if Windows Forms or WPF application
MessageBox.Show(u2.ToString());
Jonathas SucupiraPosted Aug 12, 2011, 1:13 PM
something like this:
var userResponse = new Dictionary
"name" = txtName.Text,
"age" = txtAge.Text,
"Address" = txtAddress.Text
};
Session["formAnswers"] = userResponse;