OleDbConnectionStringBuilder.Remove(String) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Removes the entry with the specified key from the OleDbConnectionStringBuilder instance.
public:
override bool Remove(System::String ^ keyword);
public override bool Remove (string keyword);
override this.Remove : string -> bool
Public Overrides Function Remove (keyword As String) As Boolean
- keyword
- String
The key of the key/value pair to be removed from the connection string in this OleDbConnectionStringBuilder.
true
if the key existed within the connection string and was removed, false
if the key did not exist.
keyword
is null (Nothing
in Visual Basic).
The following example creates a OleDbConnectionStringBuilder and demonstrates the behavior of the Remove method.
using System.Data.OleDb;
class Program
{
static void Main()
{
OleDbConnectionStringBuilder builder =
new OleDbConnectionStringBuilder();
builder.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Sample.mdb;" +
"Jet OLEDB:System Database=C:\\system.mdw;";
Console.WriteLine(builder.ConnectionString);
// Try to remove an existing item.
TryRemove(builder, "Provider");
// Try to remove a nonexistent item.
TryRemove(builder, "User ID");
// try to remove an existing item,
// demonstrating that the search isn't
// case sensitive.
TryRemove(builder, "DATA SOURCE");
Console.WriteLine("Press Enter to continue.");
Console.ReadLine();
}
static void TryRemove(OleDbConnectionStringBuilder builder,
string itemToRemove)
{
if (builder.Remove(itemToRemove))
{
Console.WriteLine("Removed '{0}'", itemToRemove);
}
else
{
Console.WriteLine("Unable to remove '{0}'", itemToRemove);
}
Console.WriteLine(builder.ConnectionString);
}
}
Imports System.Data.OleDb
Module Module1
Sub Main()
Dim builder As New OleDbConnectionStringBuilder
builder.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Sample.mdb;" & _
"Jet OLEDB:System Database=C:\system.mdw;"
Console.WriteLine(builder.ConnectionString)
' Try to remove an existing item.
TryRemove(builder, "Provider")
' Try to remove a nonexistent item.
TryRemove(builder, "User ID")
' Try to remove an existing item,
' demonstrating that the search is not
' case sensitive.
TryRemove(builder, "DATA SOURCE")
Console.WriteLine("Press Enter to continue.")
Console.ReadLine()
End Sub
Sub TryRemove(ByVal builder As OleDbConnectionStringBuilder, _
ByVal itemToRemove As String)
If builder.Remove(itemToRemove) Then
Console.WriteLine("Removed '{0}'", itemToRemove)
Else
Console.WriteLine("Unable to remove '{0}'", itemToRemove)
End If
Console.WriteLine(builder.ConnectionString)
End Sub
End Module
Because the Remove method returns a value that indicates its success, it is not required to look for the existence of a key before trying to remove the key/value pair from the OleDbConnectionStringBuilder instance.
Product | Versions |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
.NET feedback
.NET is an open source project. Select a link to provide feedback: