Click here to Skip to main content
15,886,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have create database in access.
how can i login throw database.
plz help me...

[ when in click on login button so will go on next from.. throw database..(some thing like that) ]
(my code)


C#
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;
using Arbuda_Bangles.AB_DBDataSetTableAdapters;

namespace Arbuda_Bangles
{
    public partial class Form1 : Form
    {
        private OleDbConnection OleConn;
        public Form1()
        {
            InitializeComponent();
            //myCon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\\VirtueNic\\Arbuda Bangles\\Arbuda Bangles\\Arbuda Bangles\\AB_DB.accdb");
            string strconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\\VirtueNic\\Arbuda Bangles\\Arbuda Bangles\\Arbuda Bangles\\AB_DB.accdb";
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'aB_DBDataSet.User_Master' table. You can move, or remove it, as needed.
            this.user_MasterTableAdapter.Fill(this.aB_DBDataSet.User_Master);
            usertxt.Text = "";
            passtxt.Text = "";
        }
        private void butLogin_Click(object sender, EventArgs e)
        {
            //string strconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\\VirtueNic\\Arbuda Bangles\\Arbuda Bangles\\Arbuda Bangles\\AB_DB.accdb";
           // string strcmd = "select User_Master,Password from Users";
           // OleDbConnection OleConn = new OleDbConnection(strconn);
          //  OleDbCommand OleCmd = new OleDbCommand(strcmd, OleConn);
         //   OleConn.Open();
          //  // OleDbDataReader OleRead = OleCmd.ExecuteReader();
           // Welcome form = new Welcome();
          //  form.Show();
          //  OleConn.Close();

            //OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\\VirtueNic\\Arbuda Bangles\\Arbuda Bangles\\Arbuda Bangles\\AB_DB.accdb");
            //OleDbCommand com = new OleDbCommand("SELECT username,password FROM User_Master", con);
            //OleDbDataReader reader;
            //bool permit = false;
            //try
            //{
              //  con.Open();
                //reader = com.ExecuteReader();
                //while (reader.Read())
                //{
                  //  if (InputName == (reader["username"].ToString()) && InputPass == reader["password"].ToString())
                   // {
                     //   permit = true;
                       // break;
                    //}
                //}
                //con.Close();
          //  }
           // catch (Exception ex)
         //   {
         //       MessageBox.Show(ex.Message);
         //   }
         //   if (permit == true)
         //       MessageBox.Show("Access granted");
         //   else
           //     MessageBox.Show("Acces denied");

          // OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\\VirtueNic\\Arbuda Bangles\\Arbuda Bangles\\Arbuda Bangles\\AB_DB.accdb");
          // OleDbCommand cmd = new OleDbCommand("SELECT username,password FROM User_Master", con);
          //  OleDbDataReader read;
         //   try
         //   {
           //     cmd = new OleDbCommand("SELECT username,password FROM User_Master", con);
           //     //cmd = new OleDbCommand("SELECT username FROM User_Master WHERE password =" + Convert.ToInt32(passtxt.Text), con);
            //    if (con.State == ConnectionState.Closed)
            //        con.Open();
            //    read = cmd.ExecuteReader();
               // read.Read();//You should read only once because you can //retrieve only one record(i.e, User_Name is unique)
              //  usertxt.Text = read["username"].ToString();

               // read.Close();
               // con.Close();

        }

    }
}
Posted
Comments
Dave Kreskowiak 9-Dec-10 10:07am    
"throw database"?? What does this mean? I'm guessing that you're trying to write a method that verifies a username and password against a database, but your code is so messed up, it doesn't make much sense.
MCY 11-Dec-10 11:53am    
what is "throw database"??
[no name] 13-Dec-10 4:18am    
Me also have the same query?
Toli Cuturicu 17-Dec-10 21:51pm    
If you really want to throw your database away... then may I suggest not to create it in the first place?
Rob Branaghan 31-Jan-11 13:45pm    
The CodeProject user wants to log in USING the database.

Anyways

Vishalzala, Do you have a password to access your database?

I would suggest visiting this website. http://www.connectionstrings.com/access-2007 this shows you what connection string to use.

http://www.java2s.com/Tutorial/CSharp/0560__ADO.Net/ReaddatafromAccessdatabase.htm[^]

That website shows you how to open and query the Access Database.

I would suggest seperating your code into Methods and functions and keep Database areas ina Data Access Layer and Business Logic Layer, rather than having it all in button click.



Good luck with your project
 
Share this answer
 
how to read from a database of access is given in the links here[^] and the link in answer 1.
The point I would like to point out is that if you are storing your passwords on the access database as they are (in other words, say a password is "123abc", and you put this into the database as "123abc"), anybody who could use the database will see the usernames and passwords.
A more convenient approach would be storing MD5 or SHA2 values of the passwords. In the check, you compare the hashed value of the password entered with the hashed value stored. In this manner, even if someone sees the database, he will not be able to get the pass codes.
Of course one down side is, you will not be able to recover lost passwords; they should be reset since they cannot be de-hashed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900