CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Starting Database....

    Hello! This is my first project on database....what I want to do is a login page which checks the Username and Password detail from the database and lets in if UserName is true.....

    I have created a service-based database named UserInfo.mdf which has a table with 2 columns called UserName and Password......I have also added a values to these columns......Now on the login screen I want to compare the values from the user in Textbox with this value in the database.....and If this matches it must login.......
    Please guide me in here what else should I add or do to make it work??


    Please Evaluate my attached project.....
    Last edited by rocky_upadhaya; February 12th, 2010 at 03:19 AM.

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: [RESOLVED] Starting Database....

    You can go way of asp.net and mebership provider, or do it youself with SQL query to DB. In this case, you will need DbConnection (SqlConnection?) and DbCommand executed with ExecuteReader() method of it.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  3. #3
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Starting Database....

    Thanks You for your suggestion....Here is a Updated Program...please have a look through it....
    I managed to validate user through the database data but i need help for changing and updating data and database........
    I am having a problem in the second window where I want to change password over writing the current password in the data base.....
    Last edited by rocky_upadhaya; February 14th, 2010 at 03:16 AM.

  4. #4
    Join Date
    Feb 2010
    Posts
    25

    Re: [RESOLVED] Starting Database....

    Do you need it to be with a DB? If it is a single user/pass account it can be easilly saved in binary file. I have a similar project - on first run it creates an account (user chosen user and pass) and on each other run, you need to use the user and pass you have chosen to get to form2.

    If that would be any help I can provide you with the source code of my project.

  5. #5
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: [RESOLVED] Starting Database....

    Yes I would surely like to see that....Please Upload it here.....On the Other Hand I used database Because I have a plan of extending this application and I surely need the database on that so that I can only add a table to it....any oh! it would be great if I can see your application...Thanks

  6. #6
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: [RESOLVED] Starting Database....

    Someone have suggested me the following code for solving my problem..but it is not updating the data base at all even though it does not give any error at compile or runtime....please have a look at this l...
    Code:
    private void button1_Click(object sender, RoutedEventArgs e)
    {
        using (var db = new DataClasses1DataContext())
        {
            
            var user = db.usrInfo_tables.SingleOrDefault(c => c.Username == txt_usrname.Text.Trim() && c.Password == txt_oldpass.Text.Trim());
    
            if (user == null)
            {
                MessageBox.Show("Incorrect Username or Old Password!!");
                return;
            }
    
            user.Password = txt_newpass.Text.Trim();
            db.SubmitChanges();
        }
    }

  7. #7
    Join Date
    Feb 2010
    Posts
    25

    Re: [RESOLVED] Starting Database....

    Here is the login modul. I am pretty sure that you can use this file instead of DB, but I am not advance enough to tell you how..

    Also check this code, wrote it fast just to show u what i meant:

    private void button3_Click(object sender, EventArgs e)
    {
    string username = textBox1.Text;
    string password = textBox2.Text;
    string username1, password1;
    var db = new databaseDataContext();
    var user = db.Users.Single(a => a.ID == 1); // get the user with ID = 1
    username1 = user.Username;
    password1 = user.Password;
    if ((username == username1) && (password == password1))
    {
    MessageBox.Show("OK");

    }

    You need to change the ID for the account to 1 for this to work.
    Attached Files Attached Files
    Last edited by lost_bg; February 12th, 2010 at 12:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured