I am trying to find the sum of a column( cal) between two dates and then assign or display the result (sum) in a textbox or label in C#. Please help me.

MySqlConnection mycon = new MySqlConnection("datasource=localhost;username=root;database=church");
            mycon.Open();
            MySqlCommand get = new MySqlCommand("SELECT  sum(cal) from tithes where transdate between '" + from + "' and '" + to + "'");
            MySqlDataReader reade = get.ExecuteReader();
            label4.Text = reade.ToString();
            mycon.Close();

Don't use ExecuteReader() for a single scalar value, use ExecuteScalar() instead. This is more along the lines of what you're trying to accomplish:

private static string GetMemberFilePath(int memberid)
    {
      const string query = @"Select FName From MemberInfo Where MemberId = @MemberId";
      using (SqlConnection conn = new SqlConnection(connStr))
      {
        conn.Open();
        using (SqlCommand cmd = new SqlCommand(query, conn))
        {
          cmd.Parameters.Add(new SqlParameter("@MemberId", SqlDbType.Int)).Value = memberid;
          string result = Convert.ToString(cmd.ExecuteScalar());
          return result;
        }
      }
    }

That will return a string value which you can set to the .Text property of a control.

Can u please use my query and then assign or display it in a textbox for me.

SAINTJAB>Can u please use my query and then assign or display it in a textbox for me.

What did you expect it to do? Do you get any errors? We only give help to those who show effort. You might want to read the homework policy if you run into problems and want to ask for help here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.