Mathematical operation from datatable inserted values in only one textbox

  • Hi , i'm new to c# programming my objective is to type an operation (operands and operators) in a single expressionTextBox and if I click on a resultButton the result will be displayed.

    For example, i have 3 variables of type float named var1, var2 and var3 (in a table of data with their content values ) I want to write in the expressionTextBox var2 + var3= (or *or -or sinor cos...) and the result of var1 will be displayed in ResultTextbox.

    The textbox has to be able to understand more than one variable from datatable and has to understand operands and functions for the operation. Itried with a code, can someone help me to do that my problem is in the first textbox (expressionTextbox) because i know how to update the result in var1 , are there other methods using listBox, for example?

    This is a first step below. Am I on the right path?please help !

    private void ResultButton_Click(object sender, EventArgs e)
            string[] parts = expressionTextbox.Text.Split('+');
            double intSum = 0;
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.CommandText = "select * from Table_com where Variable=@variable";
            cmd.Parameters.Add("@variable", SqlDbType.VarChar).Value = expressionTextbox.Text;
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            foreach (DataRow dr in dt.Rows)
                intSum = intSum + Convert.ToDouble(dr["Contents"]);
            ResultTextbox.Text = intSum.ToString();

Log in to reply