Hi...
This is my main form

And above table is my transaction table for above form....
so the query is like...
when i will select the month from datetimepicker as march 2013.. den it should display the
the value of month from respective 3 gridviews in their respective textbox as shown in above form (for eg:Total donation=10000,monthly expenditure=30,event expenditure=6160)...
Now logic is dat....
monthly donation + previous balance-monthly expenditure+event expenditure=balance
Nw on selection of month the data should be displayed in textboxes n d previous balance (means balance of feb) should be displayed at that event...
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 ngoo
{
public partial class Transaction : Form
{
public Transaction()
{
InitializeComponent();
}
SqlConnection con = new SqlConnection("Data Source=ABCD;Initial Catalog=Ngo;Integrated Security=True");
private void Donations_Load(object sender, EventArgs e)
{
dateTimePicker1.CustomFormat = "MMMM yyyy";
dateTimePicker1.ShowUpDown = true;
dataGridView3.CellClick += new DataGridViewCellEventHandler(dataGridView3_CellClick);
dataGridView2.CellClick += new DataGridViewCellEventHandler(dataGridView2_CellClick);
dataGridView4.CellClick += new DataGridViewCellEventHandler(dataGridView4_CellClick);
textBox7.ReadOnly = true;
try
{
DataTable dt = new DataTable();
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select month(Date) as Month,year(Date) as year,sum(Rupees) as Total from Donors group by month(Date),year(Date)", con);
SqlDataAdapter sda1 = new SqlDataAdapter("select month(Date) as Month,year(Date) as year,sum(Total) as Total from Des_eve_exp group by month(Date),year(Date)", con);
SqlDataAdapter sda2 = new SqlDataAdapter("select month(Week) as Month,year(Week) as year,sum(GrandTotal) as Total from Week_Exp group by month(Week),year(Week)", con);
sda.Fill(dt);
sda1.Fill(dt1);
sda2.Fill(dt2);
dataGridView3.DataSource = dt;
dataGridView2.DataSource = dt1;
dataGridView4.DataSource = dt2;
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
}
SqlCommand cmd = new SqlCommand("select sum(Rupees) as Rupees from Donors ", con);
SqlDataReader rdr1 = cmd.ExecuteReader();
while (rdr1.Read())
{
textBox1.Text = (rdr1["Rupees"].ToString());
}
if (rdr1 != null)
rdr1.Close();
cmd.ExecuteNonQuery();
con.Close();
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
textBox7.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
}
}
private void tabPage2_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select month(Date) as Month,year(Date) as Year,sum(Rupees) as Total from Donors group by Month(Date),year(Date)", con);
cmd.ExecuteNonQuery();
con.Close();
}
private void dataGridView3_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
string a;
a = textBox6.Text;
textBox6.Text = dataGridView3.Rows[e.RowIndex].Cells[2].Value.ToString();
}
}
private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
textBox5.Text = dataGridView2.Rows[e.RowIndex].Cells[2].Value.ToString();
}
}
private void dataGridView4_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
textBox2.Text = dataGridView4.Rows[e.RowIndex].Cells[2].Value.ToString();
}
}
private void button1_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32( textBox6.Text);
int b = Convert.ToInt32(textBox4.Text);
int c = a + b;
int d = Convert.ToInt32(textBox2.Text);
int e1 = Convert.ToInt32(textBox5.Text);
int f = d + e1;
int g = c - f;
textBox3.Text = g.ToString();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
DateTime selectedDate = dateTimePicker1.Value;
DateTime lastDayOfMonth = new DateTime(
selectedDate.Year,
selectedDate.Month,
DateTime.DaysInMonth(selectedDate.Year, selectedDate.Month));
}
}
}