DbConnectionStringBuilder.Remove(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从 DbConnectionStringBuilder 实例中移除具有指定的键的项。
public:
virtual bool Remove(System::String ^ keyword);
public virtual bool Remove (string keyword);
abstract member Remove : string -> bool
override this.Remove : string -> bool
Public Overridable Function Remove (keyword As String) As Boolean
参数
- keyword
- String
要从此 DbConnectionStringBuilder 中的连接字符串移除的键/值对中的键。
返回
如果该键存在于连接字符串中并已被移除,则为 true
;如果该键不存在,则为 false
。
例外
keyword
为 Null(在 Visual Basic 中为 Nothing
)
示例
static void Main()
{
DbConnectionStringBuilder builder = new
DbConnectionStringBuilder();
builder.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Demo.mdb;" +
"Jet OLEDB:System Database=system.mdw;";
// 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.ReadLine();
}
static void TryRemove(DbConnectionStringBuilder builder, string itemToRemove)
{
if (builder.Remove(itemToRemove))
{
Console.WriteLine(@"Removed '{0}'", itemToRemove);
}
else
{
Console.WriteLine(@"Unable to remove '{0}'", itemToRemove);
}
Console.WriteLine(builder.ConnectionString);
}
Sub Main()
Dim builder As New DbConnectionStringBuilder
builder.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Demo.mdb;" & _
"Jet OLEDB:System Database=system.mdw;"
' 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.ReadLine()
End Sub
Sub TryRemove(ByVal builder As DbConnectionStringBuilder, _
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
此示例显示以下输出:
Removed 'Provider'
data source=C:\Demo.mdb;jet oledb:system database=system.mdw
Unable to remove 'User ID'
data source=C:\Demo.mdb;jet oledb:system database=system.mdw
Removed 'DATA SOURCE'
jet oledb:system database=system.mdw
注解
Remove由于 方法返回一个值,该值指示其成功,因此在尝试从实例中删除键/值对之前,不需要查找密钥DbConnectionStringBuilder。