Link to home
Start Free TrialLog in
Avatar of amillyard
amillyardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

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))
            {
                FORTUNEConnection1.Open();

                SqlCommand scCommand = new SqlCommand((String.Format("SELECT [MasterAccount_ID] FROM [MasterAccounts] WHERE [MasterAccount_ID] = '{0}'", TextBox_SearchMasterAccounts.Text)), FORTUNEConnection1);
                MasterAccountSearch_ID = (string)scCommand.ExecuteScalar();
                FORTUNEConnection1.Close();
            }
Avatar of surajguptha
surajguptha
Flag of United States of America image

>> 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
ASKER CERTIFIED SOLUTION
Avatar of surajguptha
surajguptha
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of amillyard

ASKER

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,