0
votes
  1. From Datatable to dataGridView using filter. I have Datatable, how to insert data from this Datatable to dataGridView, where column value must be equivalent to specific value.

Like SQL-command: select * from testTable where name = 'test'

  1. Changing values in dataGridView I want to select some rows in dataGridView and by clicking a button, change value in columns of selected rows. And then changes from dataGridView must apply to Datatable (dataGridView source).

  2. Count From Datatable using filter.

How can I count rows from Datatable, where column value must be equivalent to specific value.

Like SQL-command: SELECT COUNT(id) FROM Ticket Where name = 'test'

2

2 Answers

0
votes

tUse DataAdapter to Fill Data in a DataSet,Use it as Source for DataGridView,Afer you have made changes just call .update();

public SqlDataAdapter sda { get; set; }
public DataSet ds { get; set; }    
public Form2()
    {
       InitializeComponent();
       sda = new SqlDataAdapter("select * from testTable where name = 'test'",connection_string);
            ds=new DataSet();
            dataGridView1.DataSource = ds;
    }
    private void Update_Click(object sender, EventArgs e)
    {
        sda.Update(ds);
    }

For Changing Value of columns of multiple column on Button Click

private void Change_ColumnValue_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow  row in dataGridView1.SelectedRows)
            {
                ds.Tables[0].Rows[row.Index]["Column_Name"] = row.Cells["Column_Name"].Value;
            }
    }

For Counting Rows using a Filer use Following Code

ds.Tables[0].Select("Column_Name='value'").Count();
0
votes

You will have to bind the datatable to the datagridview.

Just have a look at the following liks:

http://msdn.microsoft.com/library/fbk67b6z(v=vs.110).aspx

or at stackoverflow...

how to bind datatable to datagridview in c#

How Bind DataTable to DataGrid