Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Operation from datatable inserted values in only one textbox

jig. Bire
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 17, 2019 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
atlassian, jira service management, jsm webinar, ai in jsm, opsgenie integration, incident management, virtual agent, atlassian intelligence, ai-powered service desk, it operations, atlassian learning, service management webinar, team '25 recap

What’s new in Jira Service Management 🤔

Discover how Atlassian is revolutionizing service management with cutting-edge solutions for AI-powered support, HR Service Management, or DevOps connectivity.

Register here ⬇️
AUG Leaders

Atlassian Community Events