* add controls dg1(datagridview),dg2(datagridview),btnCopy2Dg2 (button)
* when you click on the button the selected row of dg1 is copied to dg2 and hope this helps
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
DataSet ds1= new DataSet() ;
DataSet ds2= new DataSet() ;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
SqlConnection oConn = new SqlConnection("Data Source=SOLAP;Database=Sample;user=sa;password=admin1990");
oConn.Open();
SqlCommand oCmd = new SqlCommand("select companyname,address from customers", oConn);
SqlDataAdapter oda1 = new SqlDataAdapter(oCmd);
oda1.Fill(ds1);
dg1.DataSource = ds1.Tables[0].DefaultView;
SqlCommand oCmd2 = new SqlCommand("select companyname,address from customerscopy", oConn);
SqlDataAdapter oda2 = new SqlDataAdapter(oCmd2);
oda2.Fill(ds2);
dg2.DataSource = ds2.Tables[0].DefaultView;
MessageBox.Show("OK");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnCopy2Dg2_Click(object sender, EventArgs e)
{
DataGridViewSelectedRowCollection oSoruceRow = dg1.SelectedRows;
var x=ds2.Tables[0].Rows.Add();
x[0] = oSoruceRow[0].Cells[0].Value ;
x[1] = oSoruceRow[0].Cells[1].Value;
}
}
}