3/3/2015
12:36:40 PM
By selecting employee ID
The salary should change on chart in C# (Windows Application)
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Deepak RatanPosted Mar 3, 2015, 6:48 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace csharpcorner
{
public partial class chart : Form
{
public chart()
{
InitializeComponent();
Load1();
}
public SqlConnection connection
{
get;
set;
}
public SqlCommand command
{
get;
set;
}
protected void Load1()
{
ErrorHandling Err = new ErrorHandling();
try
{
var ConnectionString = ConfigurationManager.ConnectionStrings["Myconnection"].ConnectionString;
SqlConnection Connect = new SqlConnection(ConnectionString);
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
string sqlquery = "select es.EmpSalary,es.EmpID,ed.Employee_Name from Employee_Salary_Detail es inner join Employee_details ed on es.EmpID=ed.EmpID";
Connect.Open();
command = new SqlCommand(sqlquery, Connect);
adapter.SelectCommand = command;
adapter.Fill(ds);
cmbempidchart.DataSource = ds.Tables[0];
cmbempidchart.ValueMember = "EmpID";
cmbempidchart.DisplayMember = "EmpID";
Connect.Close();
if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0 && ds != null)
{
this.Employeechart.Series["Employeeseries"].Points.AddXY(ds.Tables[0].Rows[0]["Employee_Name"], ds.Tables[0].Rows[0]["EmpSalary"]);
}
}
catch (Exception Ex)
{
string ErrorMessage = Err.CreateErrorMessage(Ex);
Err.LogFileWrite(ErrorMessage);
}
}
private void chart_Load(object sender, EventArgs e)
{
}
private System.Data.DataTable GetData(string query)
{
throw new NotImplementedException();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnbackchart_Click(object sender, EventArgs e)
{
new Form1().Show();
this.Hide();
}
private void cmbempidchart_SelectionChangeCommitted(object sender, EventArgs e)
{
string val = cmbempidchart.SelectedValue.ToString();
ErrorHandling Err = new ErrorHandling();
try
{
var ConnectionString = ConfigurationManager.ConnectionStrings["Myconnection"].ConnectionString;
SqlConnection Connect = new SqlConnection(ConnectionString);
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds1 = new DataSet();
string sqlquery = "select es.EmpSalary,es.EmpID,ed.Employee_Name from Employee_Salary_Detail es inner join Employee_details ed on es.EmpID=ed.EmpID where es.EmpID='" + val + "'";
Connect.Open();
command = new SqlCommand(sqlquery, Connect);
adapter.SelectCommand = command;
adapter.Fill(ds1);
Connect.Close();
if (ds1.Tables[0] != null && ds1.Tables[0].Rows.Count > 0 && ds1 != null)
{
this.Employeechart.Series["Employeeseries"].Points.AddXY(ds1.Tables[0].Rows[0]["Employee_Name"], ds1.Tables[0].Rows[0]["EmpSalary"]);
}
}
catch (Exception Ex)
{
string ErrorMessage = Err.CreateErrorMessage(Ex);
Err.LogFileWrite(ErrorMessage);
}
}
}
}