1

I am able to open the data grid connection , Now in data grid after opening i want to update particuar value through text box. But how should I update using grid.

Below is the code

    private void button3_Click(object sender, EventArgs e)
    {
        SQLiteConnection connection4 = new SQLiteConnection(@"Data Source = C:\foo.sqlite;Version =3");
        connection4.Open();
        string sql2 = "Update Table set language1= '" + textBoxUpdate1.Text + "' where language1 = '" + textBox_Search.Text + "'";
        SQLiteDataAdapter connect4 = new SQLiteDataAdapter(sql2, connection4);
        DataSet ds4 = new DataSet();
        connect4.Fill(ds4);
        dataGridView.DataSource = ds4.Tables[0];
    }

Data grid view

From the image i want to say that i want to update the language 2 , so i will type in the second text box where in the update statement i will set but "where" i want to choose where the user highlights in the data grid , below is the update table where datagrid selection is there , at that place i want data grid selected

like

    string sql2 = "Update Table set language1= '" + textBoxUpdate1.Text + "' where language1 = '" + DATAGrid Selection + "'"; 

Is this possible?

1
  • Don't forget to dispose of your SQLiteConnection. Suggest wrapping this code in Using Commented Nov 21, 2012 at 11:17

2 Answers 2

1

The DataGridView exposes properties you can examine to pull out what is selected. You can find more information in this MSDN Link

Sign up to request clarification or add additional context in comments.

Comments

0

Run the below code to edit particular thing from the grid. Just edit at the grid and press the update button. Form the below code you can edit the particular row by editing on it and press the update button

  private void button3_Click(object sender, EventArgs e)
    {
        DataTable dt = dataGridView.DataSource as DataTable;
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (dt.Rows[i].RowState == DataRowState.Modified)
            {
                MessageBox.Show(dt.Rows[i][3].ToString());
            }
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.