enter a case/account number (via a form text field), press the submit button (to search/find account).

Posted on 2007-10-11
Last Modified: 2013-11-26
Development Platform: c#, 2.x, Visual Studio Pro utilising Web Developer, IIS 6, SQL Server 2005

Want to be able to enter a case/account number (via a form text field), press the submit button (to search/find account).

return back some of the record fields (columns) pertaining to that account record...also, if record not find (i.e. typed an incorrect account number, an error message indicating so).

Below I have a script that worked with finding the first successful response in database -- as we are searching for unique account numbers within database, assuming this is still the better way forward for getting some of the account details.

Previously, I used this script to return a string value -- but this time, am returning the index/integer field -- cannot seem to get this to work properly (conversion issue).

Also, how do I pull back more fields from the same record (like, name, address etc).

Thank you in advance for your time and efforts with this enquiry.

            SqlDataSource FORTUNESQLDataSource = new SqlDataSource();
            FORTUNESQLDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["FORTUNEConnectionString"].ToString();

            string MasterAccountSearch_ID = "";
            using (SqlConnection FORTUNEConnection1 = new SqlConnection(FORTUNESQLDataSource.ConnectionString))

                SqlCommand scCommand = new SqlCommand((String.Format("SELECT [MasterAccount_ID] FROM [MasterAccounts] WHERE [MasterAccount_ID] = '{0}'", TextBox_SearchMasterAccounts.Text)), FORTUNEConnection1);
                MasterAccountSearch_ID = (string)scCommand.ExecuteScalar();
Question by:amillyard
    LVL 21

    Expert Comment

    >> how do I pull back more fields from the same record (like, name, address etc).

    Just add the columns you need to the query

    SELECT [MasterAccount_ID],name, address, watever FROM [MasterAccounts] WHERE [MasterAccount_ID] = '{0}'", TextBox_SearchMasterAccounts.Text)), FORTUNEConnection1
    LVL 21

    Accepted Solution

    And instead of using execute Scalar use ExecuteDataSet and get a dataset from where you can read these details

    Author Comment

    ok, understand what you are saying with both comments.

    the workflow is that there is a search box (enter text), then press submit to check if account is available.

    once the account has been found (confirmed) -- the asp page stores that account number in a session variable as the current account working on -- then redirects to another asp page, which then upon loading page, gets the relevant table information and subsequently use the dataset as recommended above -- this redirected page knows what account to pull by using the session variable stored for reference just earlier.

    what am I needing further advise on then?

    1. the above scripting (or alternative) -- to simply check if a record exists and return a variable response indicating found or not found.

    2. MasterAccountSearch_ID = (string)scCommand.ExecuteScalar();
    this part compiles ok -- but not works online as the MasterAccountSearch_ID is a string, but the database record variable is an Int (primary key field) -- would do not I need to change on that line?

    many thanks,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now