3 Replies - 14923 Views - Last Post: 09 October 2013 - 05:49 AM Rate Topic: -----

#1 TitanWizardDemon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-February 10

Login in C# with an Access Database

Posted 22 February 2010 - 06:48 PM

Hi. I am new to C# and I am very confused about connecting it with my Access database.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private OleDbConnection mycon;
        public Form1()
        {
            
           mycon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\user\My Documents\login.mdb;Persist Security Info=False");
            InitializeComponent();
            mycon.Open();
            

            
        }

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

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

        private void login_Click(object sender, EventArgs e)
        {
            string x =usename.Text;
            DataSet ds = new DataSet();
            OleDbDataAdapter adapter =
            new OleDbDataAdapter("Select * from login where username="+usename.Text+"and password="+passname.Text, mycon);
            
            MessageBox.Show("The username is "+usename.Text+" and the password is"+passname.Text ,"Test Message");
        }
    }
}




You see, what I want to achieve is when I input the right values in the username and password textfield, when I click the login button, the program will check the database if the username and password exists. But I dont know how. This is really hard for me. Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Login in C# with an Access Database

#2 Sn0wBum  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 178
  • Joined: 04-February 10

Re: Login in C# with an Access Database

Posted 24 February 2010 - 08:13 AM

Here is a link pertaining to OleDb Data Objects by PsychoCoder that you may find helpful.

http://www.dreaminco...wtopic33979.htm

This post has been edited by Sn0wBum: 24 February 2010 - 08:14 AM

Was This Post Helpful? 0
  • +
  • -

#3 Sn0wBum  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 178
  • Joined: 04-February 10

Re: Login in C# with an Access Database

Posted 26 February 2010 - 05:56 AM

This might be what you are looking for...

private  void login_Click(object sender, EventArgs e)
{
OleDBDataReader dr = null;
OleDBCommand cmd = null;
string cmdStr = "SELECT * FROM login WHERE username='"+username.Text+"' and password='"passname.Text+"' LIMIT 1";

cmd = new OleDBCommand(cmdStr,mycon);
dr = cmd.ExecuteNonReader();
cmd.Dispose();
//Check the datareader here...if dr returns 1 record...user is in DB
if(dr.Read() == true)
{
MessageBox.Show("Login Successful");
//User is in DB... do work here
}
else
{
MessageBox.Show("Invalid Credentials, Please Re-Enter");
}
dr.Dispose();

}



Hope this helps
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3621
  • View blog
  • Posts: 11,276
  • Joined: 05-May 12

Re: Login in C# with an Access Database

Posted 09 October 2013 - 05:49 AM

Please don't resurrect old threads. Create new topics if needed.

Closing this thread down.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1