0
void databaseUpdate()
{
conString = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=True";
            con = new SqlConnection(conString);
            con.Open();
            string quryString = " select * from Employees";
            da = new SqlDataAdapter(quryString, con);
            ds = new DataSet();
            da.Fill(ds, "Emp");
            //dataGridView1.DataSource = ds.Tables["Emp"];
            dataGridView1.Columns.Add("EmpID", "ID");
            dataGridView1.Columns.Add("FirstName", "FirstName");
            dataGridView1.Columns.Add("LastName", "LastName");
            int row = ds.Tables["Emp"].Rows.Count - 1;
            for (int r = 0; r<= row; r++)
            {
                dataGridView1.Rows.Add();
                dataGridView1.Rows[r].Cells[0].Value = ds.Tables["Emp"].Rows[r].ItemArray[0];
                dataGridView1.Rows[r].Cells[1].Value = ds.Tables["Emp"].Rows[r].ItemArray[1];
                dataGridView1.Rows[r].Cells[2].Value = ds.Tables["Emp"].Rows[r].ItemArray[2];
            }
	        


            con.Close();
        }
}

adapting the above, how would you update it???

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by SpiderWebs
0

Update what? You mean dgv?

1st of all, you have to put the gdv creation into a seperate method, which has to be called only ones. Another method will populate the dgv - this method can be called numerous times. And you can use DataSource to populate dgv, no need to populate it "manually" in the runtime (like for loop in the upper example).

0

By update, I mean any changes made to the datagridview are transfered to the database at the click of the update button event.
I have tried:

da.Update(ds, "Emp");

within a button event.

I have populated the datagridview manually as some columns are check boxes.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.