Unicode Property (PgSqlConnection)
On this page
Gets or sets a value indicating whether the UTF8 charset will be used.
Syntax
|
|---|
'Declaration
Public Property Unicode As Boolean |
|
|---|
public bool Unicode {get; set;} |
Property Value
true, if client charset UTF8 is used;
false, if default client charset is used. The default value is
false.
Example
The following two functions demonstrate how to use
Unicode property to implement charset-safe string transfer.
|
|---|
public void UploadString(PgSqlConnection pgSqlConnection)
{
pgSqlConnection.Unicode = true;
PgSqlCommand pgSqlCommand = new PgSqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", pgSqlConnection);
pgSqlCommand.Parameters.Add("BlockText",PgSqlType.VarChar,50).Value = "Place here some text that requires Unicode support.";
pgSqlConnection.Open();
try
{
Console.WriteLine(pgSqlCommand.ExecuteNonQuery()+" rows affected.");
}
finally
{
pgSqlConnection.Close();
}
}
public void DownloadString(PgSqlConnection pgSqlConnection)
{
pgSqlConnection.Unicode = true;
PgSqlCommand pgSqlCommand = new PgSqlCommand("SELECT * FROM Test.TextBlocks", pgSqlConnection);
pgSqlConnection.Open();
PgSqlDataReader pgSqlReader = pgSqlCommand.ExecuteReader(CommandBehavior.Default);
try
{
while (pgSqlReader.Read())
{
string myString = (string)pgSqlReader["BlockContent"];
Console.WriteLine(myString);
}
}
finally
{
pgSqlReader.Close();
pgSqlConnection.Close();
}
} |
|
|---|
Public Sub UploadString(ByVal pgSqlConnection As PgSqlConnection)
pgSqlConnection.Unicode = True
Dim pgSqlCommand As New PgSqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", pgSqlConnection)
pgSqlCommand.Parameters.Add("BlockText", PgSqlType.VarChar, 50).Value = "Place here some text that requires Unicode support."
pgSqlConnection.Open()
Try
Console.WriteLine(String.Concat(pgSqlCommand.ExecuteNonQuery(), " rows affected."))
Finally
pgSqlConnection.Close()
End Try
End Sub
Public Sub DownloadString(ByVal pgSqlConnection As PgSqlConnection)
pgSqlConnection.Unicode = True
Dim pgSqlCommand As New PgSqlCommand("SELECT * FROM Test.TextBlocks", pgSqlConnection)
pgSqlConnection.Open()
Dim pgSqlReader As PgSqlDataReader = pgSqlCommand.ExecuteReader(CommandBehavior.Default)
Try
While pgSqlReader.Read()
Dim myString As String = CType(pgSqlReader("BlockContent"), String)
Console.WriteLine(myString)
End While
Finally
pgSqlReader.Close()
pgSqlConnection.Close()
End Try
End Sub |
See Also