// Create a new OleDbParameter object and set its properties OleDbParameter param = new OleDbParameter(); param.ParameterName = "paramName"; param.OleDbType = OleDbType.VarChar; param.Size = 50; param.Value = "parameter value"; // Add the parameter to an OleDbCommand object OleDbCommand cmd = new OleDbCommand("SELECT * FROM myTable WHERE myColumn = ?", connection); cmd.Parameters.Add(param); // Execute the command OleDbDataReader reader = cmd.ExecuteReader();
// Add parameters to an OleDbCommand object using the AddWithValue method OleDbCommand cmd = new OleDbCommand("INSERT INTO myTable (col1, col2) VALUES (?, ?)", connection); cmd.Parameters.AddWithValue("@col1", "value1"); cmd.Parameters.AddWithValue("@col2", 123); // Execute the command cmd.ExecuteNonQuery();This example shows how to add parameters to an OleDbCommand object using the AddWithValue method. It then executes the command. The System.Data.OleDb namespace is a part of the .NET Framework library.