Unicode Property (PgSqlConnection)
Gets or sets a value indicating whether the UTF8 charset will be used.
public bool Unicode {get; set;}
'Declaration
Public Property Unicode As Boolean
Property Value
true, if client charset UTF8 is used;
false, if default client charset is used. The default value is
false.
The following two functions demonstrate how to use
Unicode property to implement charset-safe string transfer.
public void UploadString(PgSqlConnection pgConnection)
{
pgConnection.Unicode = true;
PgSqlCommand pgCommand = new PgSqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", pgConnection);
pgCommand.Parameters.Add("BlockText",PgSqlType.VarChar,50).Value = "Place here some text that requires Unicode support.";
pgConnection.Open();
try
{
Console.WriteLine(pgCommand.ExecuteNonQuery()+" rows affected.");
}
finally
{
pgConnection.Close();
}
}
public void DownloadString(PgSqlConnection pgConnection)
{
pgConnection.Unicode = true;
PgSqlCommand pgCommand = new PgSqlCommand("SELECT * FROM Test.TextBlocks", pgConnection);
pgConnection.Open();
PgSqlDataReader pgReader = pgCommand.ExecuteReader(CommandBehavior.Default);
try
{
while (pgReader.Read())
{
string myString = (string)pgReader["BlockContent"];
Console.WriteLine(myString);
}
}
finally
{
pgReader.Close();
pgConnection.Close();
}
}
Public Sub UploadString(ByVal pgConnection As PgSqlConnection)
pgConnection.Unicode = True
Dim pgCommand As New PgSqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", pgConnection)
pgCommand.Parameters.Add("BlockText", PgSqlType.VarChar, 50).Value = "Place here some text that requires Unicode support."
pgConnection.Open()
Try
Console.WriteLine(String.Concat(pgCommand.ExecuteNonQuery(), " rows affected."))
Finally
pgConnection.Close()
End Try
End Sub
Public Sub DownloadString(ByVal pgConnection As PgSqlConnection)
pgConnection.Unicode = True
Dim pgCommand As New PgSqlCommand("SELECT * FROM Test.TextBlocks", pgConnection)
pgConnection.Open()
Dim pgReader As PgSqlDataReader = pgCommand.ExecuteReader(CommandBehavior.Default)
Try
While pgReader.Read()
Dim myString As String = CType(pgReader("BlockContent"), String)
Console.WriteLine(myString)
End While
Finally
pgReader.Close()
pgConnection.Close()
End Try
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2