Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 27th, 2007, 05:04 AM
Registered User
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing function parameter to query


     I am creating a class file which has a function of authenticating user. It connects to database and check password verification according to the username. But the variable I use as parameter which is "username"
how to pass that value to select query . code is as below.

public Boolean AuthenticateUser(string username, string password)
        String ConStr = ("Data Source=localhost;Initial Catalog=test;user ID = sa ;Password = keyur");
        String SQL = " SELECT Password from LoginInfo WHERE UserName = '" & username & "'

        SqlConnection conn = new SqlConnection(ConStr);
        SqlCommand cmd = new SqlCommand(SQL, conn);
        String var = null;
        var = (String)cmd.ExecuteScalar();

Web Developer
Old February 27th, 2007, 08:28 AM
Friend of Wrox
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

It looks like you are coding in java. Why don't you use VBA? Anyway, without getting into java, this:

" SELECT Password from LoginInfo WHERE UserName = '" & username & "'

should be this:

"SELECT Password from LoginInfo WHERE UserName = '" & username & "'"

Did that help?


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing a parameter to an Access query! pankaj_daga Access VBA 6 November 16th, 2007 12:26 PM
Passing an Input Field to a Parameter Query stcraig BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 4 November 6th, 2006 06:06 PM
passing parameter to query vladimir Access 6 August 30th, 2006 05:39 AM
SQL query dropping parameter function... JackNimble Access 2 March 14th, 2005 04:56 PM
Passing parameter to Access query eapsokha Classic ASP Databases 2 September 16th, 2004 02:49 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.