OdbcConnectionStringBuilder.Remove(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从 OdbcConnectionStringBuilder 实例中移除具有指定的键的项。
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
要从此 OdbcConnectionStringBuilder 中的连接字符串移除的键/值对中的键。
返回
如果该键存在于连接字符串中并已被移除,则为 true
;如果该键不存在,则为 false
。
例外
keyword
为 null(在 Visual Basic 中为 Nothing
)。
示例
以下示例创建一个 OdbcConnectionStringBuilder 实例,并演示 方法的行为 Remove 。
using System.Data.Odbc;
class Program
{
static void Main()
{
OdbcConnectionStringBuilder builder =
new OdbcConnectionStringBuilder();
builder.ConnectionString =
"Driver={SQL Server};Server=(local);" +
"Database=AdventureWorks;Trusted_Connection=yes;";
Console.WriteLine(builder.ConnectionString);
// Try to remove an existing item.
TryRemove(builder, "Server");
// 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, "DATABASE");
Console.WriteLine("Press Enter to continue.");
Console.ReadLine();
}
static void TryRemove(OdbcConnectionStringBuilder 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.Odbc
Module Module1
Sub Main()
Dim builder As New OdbcConnectionStringBuilder
builder.ConnectionString = _
"Driver={SQL Server};Server=(local);" & _
"Database=AdventureWorks;Trusted_Connection=yes;"
Console.WriteLine(builder.ConnectionString)
' Try to remove an existing item.
TryRemove(builder, "Server")
' 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, "DATABASE")
Console.WriteLine("Press Enter to continue.")
Console.ReadLine()
End Sub
Sub TryRemove(ByVal builder As OdbcConnectionStringBuilder, _
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
注解
Remove由于 方法返回一个值,该值指示其成功,因此在尝试从OdbcConnectionStringBuilder实例中删除键/值对之前,不需要查找是否存在键。