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

Posted on 2007-10-11
Medium Priority
Last Modified: 2013-11-26
Development Platform: c#, asp.net 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
  • 2
LVL 21

Expert Comment

ID: 20060447
>> 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

surajguptha earned 1500 total points
ID: 20060460
And instead of using execute Scalar use ExecuteDataSet and get a dataset from where you can read these details

Author Comment

ID: 20060665
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,

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

807 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