Reputation: 6849
I have a table StaffMaster which is containing staff photograph and the datatype of that table is varbinary. so, i want to export this table into csv file format using c# code. Even i have tried to export that table manually by sql server export task. But it shows following error.
- Validating (Error)
Messages
Error 0xc0208030: Data Flow Task: The data type for "input column
"StaffPhoto" (376)" is DT_IMAGE, which is not supported. Use DT_TEXT
or DT_NTEXT instead and convert the data from, or to, DT_IMAGE using
the data conversion component.
(SQL Server Import and Export Wizard)
I know the data are stored in binary(byte[]). But, I would like to know is it possible that can i convert it to string and when i want to import it to the sql server database it should be converted into binary. So, my data will not be lost. Image size can be 100 kb to 500 kb.
I cannot store image outside of the csv file.
I am using SQL Server 2005.
Upvotes: 2
Views: 11557
Reputation: 733
Use Base64
encoding for your binary data. It converts any binary data into readable string. The code is as following
Encode
public static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
Decode
public static string Base64Decode(string base64EncodedData)
{
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
Upvotes: 8