How can I change the values ​​of access database cells programmatically, and not through a DataGridView? For example, there are several textboxes on the form, they are filled in by the user and after clicking on the button, the textboxes fields are saved in the access database

  • Complete your question. Perhaps some code will help give you the answer. - Denis Bubnov
  • It doesn't matter where the data is displayed: in a DataGridView or TextBox , the code for working with the database is exactly the same in both cases. - Alexander Petrov
  • @ 4per, thanks, did not see. But I adhere to inline selection, when code selection for “code and code-like entities” is used , I will keep in mind in the future. - Denis Bubnov

1 answer 1

I will give a simple example, click on the button - save it from the textbox :

 private void button1_Click(object sender, EventArgs e) { using (OleDbConnection conn = new OleDbConnection(connectionString)) { try { conn.Open(); string query = "UPDATE [таблица] SET [имя_колонки] = ? WHERE id = ?"; var accessUpdateCommand = new OleDbCommand(query, conn); accessUpdateCommand.Parameters.AddWithValue("имя_колонки", textBox1.Text); // текст accessUpdateCommand.Parameters.AddWithValue("id", 1); // тут напишите свой ид da.UpdateCommand = accessUpdateCommand; da.UpdateCommand.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { // обработка исключения if (conn != null && conn.State == ConnectionState.Open) { conn.Close(); } } } } 

connectionString is a database connection string.

You can also without AddWithValue , just write directly to the line what you need instead of question marks. Pro line to make it clearer, for example:

 int id = 1; string query = "UPDATE [что_обновляем] SET [имя_обновляемой_колонки] =" + textBox1.Text + " WHERE id = " + id;