Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to calculate total gross salary hoew can i do that any one tell me
i have 1>Basic Sal
2>HRD
3>DA
4>P.F
5>Gross Sal
6>Net Paid
when i enter basic salary in textbox automatically i want to come total calculate in datagridview
how can i do that any one tell me



this is my code


C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace treeview_grossalary
{
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection("Data Source=CIODEV03\\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=True");
        SqlCommand cmd = new SqlCommand();

        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            getdata();


        }
        private void getdata()
        {
            string str = "select * from gridsalry";
            SqlDataAdapter ada = new SqlDataAdapter(str, con);
            DataSet ds = new DataSet();
            ada.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
             }

        private void btnsave_Click_1(object sender, EventArgs e)
        {
            string str = "insert into gridsalry values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "')";
            con.Open();
            cmd = new SqlCommand(str, con);
            cmd.ExecuteNonQuery();
            con.Close();
            getdata();
           }
        
    }

}
Posted
Updated 7-Mar-12 0:54am
v2

In the textbox_keypress event check,
C#
e.Keychar == (char)13

13 is ASCII for enter key

So in this routine calculate your total gross amount.

Hope this will give u an idea.

If any problem please ask again.
 
Share this answer
 
Comments
rockpune 7-Mar-12 7:09am    
where i have to write this e.Keychar == (char)13
Aniket Yadav 7-Mar-12 7:15am    
In the textbox_Keypress event
rockpune 7-Mar-12 7:24am    
getting error
Aniket Yadav 7-Mar-12 7:37am    
what error did you get? please post the code of what you have done.

And tell me one thing, is it a desktop application or web based?
Do not use string concatenation to create SQL commands, this leaves your application wide open to SQL injection attacks and could destroy your entire database. Calculating gross salary is a simple matter of writing the code to do the relevant calculations according to your payroll and tax rules. Since we do not know what those rules are we cannot give you the answer.
 
Share this answer
 
In gross salary TextChanged event

we can get values
Basic Sal
HRD
DA
P.F
Gross Sal
Net Paid

in that we can add all those values...

TextBox8.Text+=....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900