There is the following code to insert a new record in the database:

System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/BD.mdb"); System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "INSERT ThemeTest (Id_theme, NameTheme, NumberQuestion, Prim) VALUES"+ "(@Id_theme , @NameTheme, @NumberQuestion, @Prim)"; cmd.Connection = sqlConnection1; cmd.Parameters.AddWithValue("@Id_theme", 5); cmd.Parameters.AddWithValue("@NameTheme", textBox1.Text); cmd.Parameters.AddWithValue("@NumberQuestion", numericUpDown1.Value); cmd.Parameters.AddWithValue("@Prim", textBox2.Text); sqlConnection1.Open(); cmd.ExecuteNonQuery(); sqlConnection1.Close(); 

Swears on the connection string: "The keyword is not supported by provide". What am I doing wrong? How to write the connection string to the local table for access?

1 answer 1

For Access, you must use OleDbConnection. SqlConnection is for the MSSQL server. Proof

You have the right string, but if you have any doubts or the connection will be configured in the program, use OleDbConnectionStringBuilder . Here are examples of connection strings in different situations.

  • Someone can then write an example for the access database. Insert a new record, for example ... I really want to see it all in the finished version. - IntegralAL
  • Well, it seems that only this change remains, it should work. Replace System.Data.SqlClient.SqlCommand with System.Data.SqlClient.OleDbConnection, it will work (there is nowhere to check). - Yura Ivanov