This may sound like some simple stuff but I'm getting lost and my professor is hard to reach so if anybody can help me I'd greatly appreciate it.
I'm writing sort of like a bank program, there is a "log-in" form, a "registration" form, and a "data access" form. My professor gave wrote us out a data set that had sample data in it so we would know when it was working. Where I'm running into trouble first is, he told us to load the data into our "main" form which is the data view but then we need to have our "log-in" form show up so that the user can log-in and be validated. What I can't get to happen is only my log-in form to show up. I've got it so that both forms are showing, but i need just the log-in and once they're confirmed just the data access to show.

My second problem is, I really didn't understand what he was talking about when he was trying to explain how to use, check, and save new inputs to and from the data set. So if anybody could give a small explanation or direct me in the right location because I've been using Google for about 2 hours now and have come up empty handed. Again any help in the right direction is very much appreciated.

Recommended Answers

All 14 Replies

since I just read the post about homework help I'm going to post what I have coded and see if anybody can help me out. Right now I have 3 forms: frmAccountData, frmLogin, frmRegister. What I'm trying to do is have the frmAccountData as my "main" form with the dataset loaded to that, but have frmLogin be the first and only form when the program is ran. Right now the code I have for frmAccountData is:

namespace Account_Access
{
    public partial class frmAccountData : Form
    {
        public frmAccountData()
        {
            InitializeComponent();
            this.accountData1.LoadData();
        }

        private void frmAccountData_Load(object sender, EventArgs e)
        {
            frmLogin lg = new frmLogin();

            lg.Show();
            this.Visible = false;
        }
    }
}

I did the "this.visible = false;" to try to get the form to be invisible so I only saw frmLogin. The code I have for frmLogin is:

namespace Account_Access
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnRegister_Click(object sender, EventArgs e)
        {
            frmRegister reg = new frmRegister();
            reg.Show();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            
        }
    }
}

I am just stuck as to what to do for this so if anybody could help me out with this problem I would really appreciate it. I know in my first post I asked a couple of things but I want to get this problem taken care of first. Thank you to anybody who can/will try to help.

Do not you need a database to store login information ,etc ?

There are a number of ways you could approach this:

1/. It does not really matter which is you main form! You can still start from the login page and move on to the main form if the user validates correctly by changing the start-up form in 'program.cs' e.g.

static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmLogin ());
        }

2/. You could use ShowDialog(). When the main form is opened show the login form as a dialogue so the user can't access the main form until they are authenticated, if the authentication fails exit the program otherwise continue e.g.

frmLogin fm = new frmLogin();

if(fm.DialogResult != DialogResult.OK)
{
    Application.Exit();
}

3/. My least favourite option would be to use a combination of form.Show() and form.Hide() to make the forms visible as you want them from the main form.


On a separate note when you define a class in c# you should name it with a capital letter e.g. FmLogin or LoginForm so that it is easy to distinguish from instances:

// Easy to confuse and when your code gets more 
// complex it will be even more difficult to read/understand.
fmLogin loginFm = new fmLogin();

// The accepted way of doing it as it is easier to differentiate 
// the instance from the class
LoginForm fmLogin = new LoginForm();

Do not you need a database to store login information ,etc ?

We have the login information stored in an XML file used as a dataset. Our teacher wrote that portion of the code and just gave us the dataset and everthing.

The showDialog() worked perfectly. Thank you very much.

I was also wondering if anybody could direct me to a place where I can learn how to save information to dataset. Our teacher is having us do this and there is nothing in the book at all. Mainly what I'm trying to do is, with my login form if they don't have a login they can hit the register button which brings up the register form. The register form then is suppose to save the information to the XML document that is our dataset so they can log in.

A DataSet is basically a collection of DataTable.

see:
http://dotnetperls.com/datatable-use
http://msdn.microsoft.com/en-us/library/aa325658(VS.71).aspx
http://msdn.microsoft.com/en-us/library/system.data.dataset(VS.71).aspx

That first website looks the best for me but it's showing how to hard code the data into the table. Would I use the same method to save it from a textbox?

For example when my login screen pops up if the user does not have a username and password they click the register button which will bring up the register form. In the register form I have "txtFName", "txtLName", "txtUserName", and "txtPassword", side note what where you saying about the naming conventions, what I'm using is how our teacher showed us to use, and from those txtboxes I need to save all that information into the dataset "ProjectDataAccess" that our teacher wrote for us.

If you have a DataTable called Users then it will probably have columns in it called 'userName' and 'password'.

You can look through it by itereating through the rows in the table. To access a record within the row you can either use the record index or the column name.

tbl.Rows[0]["name"] = txtEdit.Text;
// or
tbl.Rows[0][0] = txtEdit.Text;

using the DataSet Visualizer, we have UserName, Password, FirstName, LastName columns.

The .dll he wrote and told us to refrence is called ProjectDataAccess, and the DataSet is called accountData1. Not sure if that helps you understand, because I don't understand your last post.

Ok,

if you want to add new data to accountData1:

accountData1.Tables["UserTable"].Rows.Add("some UserName", "some Password", "some FirstName", "some LastName");

if you want to modify data in accountData1:

accountData1.Tables["UserTable"].Rows[rowIndex]["UserName"] = "some text or string variable";

if you want to remove data from accountData1:

accountData1.Tables["UserTable"].Rows.RemoveAt(rowIndex);

It's not letting me do it that way. I don't know if it works differently because the data set i have is saved as an XML file.

Have you checked to see what methods are available through the supplied dll? Is the DataSet read only?

As this is not a standard .Net dll it is impossible for me to know what its funtionality is without seeing it. I'm sure you must have been given some information on haw to use it.

yeah, i'm trying to get a hold of my teacher so I can talk to him about it, but I only see him once a week and he's not responding to email.

I have one last thing I need help with that I can not figure out what so ever. I got my log-in code and everything to work, the only problem I'm having is checking to see if the user has "account information" and loading into the form. Such as loading "accountnumber" to a textbox, but making sure it's the correct users account number, and from that loading up past transactions the same way. If anybody can help me I'd really appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.