onchange run sql query and return value

Radio1

Radio2

Textbox1 = Quantity (Default value 0)

Textbox2 = UnitCost (Default Value 0)

Textbox3 = Total (Default Value 0)

submit would write the values of all value on the page to a session variabe to be passed to the next page like

Radio1value + Radio2.value = session(product)
textbox1 = session(Quantity)
textbox2 = session(UnitCost)
textbox3 = session(TotalCost)



onchange textbox1

I need to have "if a value is not 0 in textbox1" to run an sql query like
"select UnitCost from Prices where ProductID = Radio1value + Radio2value
and Quantity = TextBox1"


to place the value returned from sql into textbox2 and then mulitplied
against textbox1 showing the total in
textbox3

Any assistance would be greatly appreciated
rmardisAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

APoPhySptCommented:
try something like this:
 
protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            if (TextBox1.Text != "0")
            {
                string connectionString = "";
                SqlConnection con = new SqlConnection(connectionString);
                con.Open();

                string query = "select TOP 1 UnitCost from Prices where ProductID = " + Radio1value + Radio2value + " and Quantity = " + TextBox1.Text;
                SqlCommand cmd = new SqlCommand(query, con);
                SqlDataReader reader = cmd.ExecuteReader();

                while ( reader.Read())
                    textbox2.text = reader["NAME OF THE COLUMN THAT RETURNS THE DESIRED VALUE"].ToString();

                textbox3.text = (int)textBox2.Text * (int)textbox1.text;
            }
        }

Open in new window


you have to of course set a proper connection string, make any adjustments to the query I provide and Inside the reader.read() where is says "NAME OF THE COLUMN THAT RETURNS THE DESIRED VALUE" you have tu put the column name where the value you want to get is stored
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rmardisAuthor Commented:
i am causing errors when trying to use this with code for the three buttons.
can you give an example page using this funciton with textbox1,textbox2 and
textbox3.

0
rmardisAuthor Commented:
i took a while but i had a typo.  works great
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.