using (OleDbConnection conn = new OleDbConnection(connStr)){
OleDbCommand cmd1 = new OleDbCommand(sql);
conn.Open();
cmd1.ExecuteNonQuery();
conn.Close();
}
When you're using using (yeah, English), then you have to define a scope in which the object (here: conn) is valid.
This scope is defined by { ... } in which your following code is placed.
Writing using (OleDbConnection conn = new OleDbConnection(connStr); ends this scope right after ; which means that following code will not have access to that object.
If you want to use using with your OleDbCommand, too, it should look like:
using (OleDbConnection conn = new OleDbConnection(connStr))
{
conn.Open();
using (OleDbCommand cmd1 = new OleDbCommand(sql))
{
cmd1.ExecuteNonQuery();
}
conn.Close();
}
If you want to know more about using, see the Microsoft Docs:
As a rule, when you use an IDisposable object, you should declare and instantiate it in a using statement. The using statement calls the Dispose method on the object in the correct way, and (when you use it as shown earlier) it also causes the object itself to go out of scope as soon as Dispose is called. Within the using block, the object is read-only and cannot be modified or reassigned.
In my last example, the scopes would look like this:
Where yellow resembles the scope of conn and orange resembles the scope of of cmd1.
If you want, you can call scope life time of the object, since it's marked as Disposed after.