Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Operation from datatable inserted values in only one textbox Edited

 

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 `sin`or `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)
    {
        con.Open();
        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;
        cmd.ExecuteNonQuery();
        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);

        foreach (DataRow dr in dt.Rows)
        {
            intSum = intSum + Convert.ToDouble(dr["Contents"]);
        }
        ResultTextbox.Text = intSum.ToString();
        con.Close();
    }

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

4,367 views 22 32
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you