Represents a variable-length stream of characters to be stored in or retrieved from the database.
This sample code consists of two routines. The first uploads a string to the server, while the second retrieves all strings contained in "BlockContent" column of the table.
public void UploadSqlText(MySqlConnection myConnection)
{
myConnection.Unicode = true;
MySqlText myTextSql = new MySqlText("This is a test text block");
MySqlCommand myCommand = new MySqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", myConnection);
myCommand.Parameters.Add("BlockText",myTextSql);
myConnection.Open();
try
{
Console.WriteLine(myCommand.ExecuteNonQuery()+" rows affected.");
}
finally
{
myConnection.Close();
}
}
public void DownloadSqlText(MySqlConnection myConnection)
{
myConnection.Unicode = true;
MySqlCommand myCommand = new MySqlCommand("SELECT * FROM Test.TextBlocks", myConnection);
myConnection.Open();
MySqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.Default);
try
{
while (myReader.Read())
{
MySqlText myTextSql = myReader.GetMySqlText(myReader.GetOrdinal("BlockContent"));
if(!myTextSql.IsNull)
{
Console.WriteLine(myTextSql.Value);
}
}
}
finally
{
myReader.Close();
myConnection.Close();
}
}
Public Sub UploadSqlText(ByVal myConnection As MySqlConnection)
myConnection.Unicode = True
Dim myTextSql As MySqlText = New MySqlText("This is a test text block")
Dim myCommand As MySqlCommand = New MySqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(3,'First',:BlockText)", myConnection)
myCommand.Parameters.Add("BlockText", myTextSql)
myConnection.Open()
Try
Console.WriteLine(String.Concat(myCommand.ExecuteNonQuery(), " rows affected."))
Finally
myConnection.Close()
End Try
End Sub
Public Sub DownloadSqlText(ByVal myConnection As MySqlConnection)
myConnection.Unicode = True
Dim myCommand As New MySqlCommand("SELECT * FROM Test.TextBlocks", myConnection)
myConnection.Open()
Dim myReader As MySqlDataReader = myCommand.ExecuteReader(CommandBehavior.Default)
Try
While myReader.Read()
Dim myTextSql As MySqlText = myReader.GetMySqlText(myReader.GetOrdinal("BlockContent"))
If Not myTextSql.IsNull Then
Console.WriteLine(myTextSql.Value)
End If
End While
Finally
myReader.Close()
myConnection.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