I want move and sum dgvA to dgvB
example data in dgvA
| ID | Name | Money |
| 1 | AAAAA | 50 |
| 2 | AAAAA | 10 |
| 3 | BBBBBB | 5 |
| 4 | BBBBBB | 10 |
| 5 | BBBBBB | 20 |
I want move And sum dgvA to dgvB
| ID | Name | Money |
| 1 | AAAAA | 60 |
| 2 | BBBBBB | 35 |
need help ....code
Please also recommended code ...
| ID | Name | Money |
| 1 | AAAAA | 50 |
| 2 | AAAAA | 10 |
| 3 | BBBBBB | 5 |
| 4 | BBBBBB | 10 |
| 5 | BBBBBB | 20 |
| ID | Name | Money |
| 1 | AAAAA | 60 |
| 2 | BBBBBB | 35 |
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.
Satyapriya NayakPosted Aug 30, 2013, 12:59 AM
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
{
public partial class Form2 : Form
{
SqlConnection con = new SqlConnection(@"server = HOME-SAT/SQLEXPRESS;data source = .; initial catalog = test; user id=sa;pwd =pintu ;integrated security = SSPI");
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
str = "select distinct Name,sum(Money)as Money from emp group by Name";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "emp");
dataGridView2.DataMember = "emp";
dataGridView2.DataSource = ds;
con.Close();
}
private void Form2_Load(object sender, EventArgs e)
{
con.Open();
str = "select * from emp";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "emp");
dataGridView1.DataMember = "emp";
dataGridView1.DataSource = ds;
con.Close();
}
}
}