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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.