views:

11

answers:

1

I've a frmEdit with datagridview that's bouned to this:

string sqlqry1 = "select p_Name from Items where p_Id=" + p_Id;
        using (SqlCeDataAdapter a = new SqlCeDataAdapter(sqlqry1, conn))
        {
            DataTable dt1 = new DataTable();
            a.Fill(dt1);
            dataGridView1.DataSource = dt1;
        }

How to edit cells and save them back to the db?, tried using this:

using (SqlCeDataAdapter a = new SqlCeDataAdapter(sqlqry1, conn))
        {
            DataTable dt1 = new DataTable();
            a.Fill(dt1);
            dataGridView1.DataSource = dt1;
            a.Update(dt1);
        }

Nothing.

Is there anyway?.

A: 

Found solution:

        SqlCeDataAdapter da;
        SqlCeCommandBuilder cmdBuilder;


        da = new SqlCeDataAdapter("select * from Items", conn);
        cmdBuilder = new SqlCeCommandBuilder(da);
        da.Fill(myDatabaseDataSet, "Items");
        myDatabaseDataSet.Tables["Items"].Rows[0]["p_Name"] = dataGridView1.Rows[0].Cells["p_Name"].Value.ToString();
        da.Update(myDatabaseDataSet, "Items"); 
DanSogaard