Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Find user & password in Access DB.

Find user & password in Access DB.

Scheduled Pinned Locked Moved C#
databasehelpquestion
4 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sea
    wrote on last edited by
    #1

    I'm writing a small app, and I have to prepare a form which will authenticate users. This is the code I wrote. The problem is I get exception in the marked line : "no value given for for on or more required parameters" What is wrong with it? Table name is users. Column name is UserName public void userExists(string username) { try {//SQL statements string sqlFinduser = "SELECT COUNT(UserName) AS UserNameExists " + "FROM users " + "WHERE (UserName=" + username + ")"; //Command object OleDbCommand cmdFindsqlFinduser = new OleDbCommand(); cmdFindsqlFinduser.Connection = cnSurvey; cmdFindsqlFinduser.CommandType = CommandType.Text; cmdFindsqlFinduser.CommandText = sqlFinduser; //Connect cnSurvey.Open(); //Execute command int count = int.Parse(cmdFindsqlFinduser.ExecuteScalar().ToString()); //error is right here bool exists = count != 0 ? true : false; //Disconnect cnSurvey.Close(); //Return result // return exists; } catch(Exception ex) { MessageBox.Show(ex.Message); } } TIA, Ronen

    G M 2 Replies Last reply
    0
    • S sea

      I'm writing a small app, and I have to prepare a form which will authenticate users. This is the code I wrote. The problem is I get exception in the marked line : "no value given for for on or more required parameters" What is wrong with it? Table name is users. Column name is UserName public void userExists(string username) { try {//SQL statements string sqlFinduser = "SELECT COUNT(UserName) AS UserNameExists " + "FROM users " + "WHERE (UserName=" + username + ")"; //Command object OleDbCommand cmdFindsqlFinduser = new OleDbCommand(); cmdFindsqlFinduser.Connection = cnSurvey; cmdFindsqlFinduser.CommandType = CommandType.Text; cmdFindsqlFinduser.CommandText = sqlFinduser; //Connect cnSurvey.Open(); //Execute command int count = int.Parse(cmdFindsqlFinduser.ExecuteScalar().ToString()); //error is right here bool exists = count != 0 ? true : false; //Disconnect cnSurvey.Close(); //Return result // return exists; } catch(Exception ex) { MessageBox.Show(ex.Message); } } TIA, Ronen

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      That means that you have one or more names in your query that the database does not regognise. You have forgotten the apostrophes around the value for username. The database will try to interpret the username as being an identifier, not a string. --- b { font-weight: normal; }

      1 Reply Last reply
      0
      • S sea

        I'm writing a small app, and I have to prepare a form which will authenticate users. This is the code I wrote. The problem is I get exception in the marked line : "no value given for for on or more required parameters" What is wrong with it? Table name is users. Column name is UserName public void userExists(string username) { try {//SQL statements string sqlFinduser = "SELECT COUNT(UserName) AS UserNameExists " + "FROM users " + "WHERE (UserName=" + username + ")"; //Command object OleDbCommand cmdFindsqlFinduser = new OleDbCommand(); cmdFindsqlFinduser.Connection = cnSurvey; cmdFindsqlFinduser.CommandType = CommandType.Text; cmdFindsqlFinduser.CommandText = sqlFinduser; //Connect cnSurvey.Open(); //Execute command int count = int.Parse(cmdFindsqlFinduser.ExecuteScalar().ToString()); //error is right here bool exists = count != 0 ? true : false; //Disconnect cnSurvey.Close(); //Return result // return exists; } catch(Exception ex) { MessageBox.Show(ex.Message); } } TIA, Ronen

        M Offline
        M Offline
        malharone
        wrote on last edited by
        #3

        How about changing (UserName=" + username + ")" to (UserName='" + username + "')" assume: username = "abc" Current code: (UserName = abc) Fixed code: (UserName = 'abc')

        M 1 Reply Last reply
        0
        • M malharone

          How about changing (UserName=" + username + ")" to (UserName='" + username + "')" assume: username = "abc" Current code: (UserName = abc) Fixed code: (UserName = 'abc')

          M Offline
          M Offline
          Matt Gerrans
          wrote on last edited by
          #4

          :sigh: How about using Parameters instead of duct-taping together your SQL statements? Visual Basic and Visual C# Concepts - Parameters in Data-Adapter Commands[^] Doesn't everyone know about the security holes in the duct-tape approach, yet? By the way, are you storing the password in the db in plain text? Matt Gerrans

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups