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 實例中移除索引鍵/值組之前,不需要尋找索引鍵是否存在。