Chris wrote:
I need to load an rtf file to my sql database (into image type
column). now I am using external tool textcopy.exe (launched within
my application)
Is it possible (how to do that) to write my own application that will
load a file into image type column in sql db?
Of course! Something along these lines (untested code - may not even
compile):
using System;
using System.Data;
using System.Data.SqlClient;
using System.IO
class Loader
{
public static void Main(string[] args)
{
byte[] image = null;
using (FileStream fs = new FileStream(
args[0],
FileMode.Open,
FileAccess.Read,
FileShare.Read
))
{
image = new byte[fs.Length];
fs.Read(image,0,image.Length);
}
}
using (SqlConnection con = new SqlConnection("my connection string"))
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "insert into MyTable (MyImageColumn) values
(@Image)";
cmd.Paramters.Add("@Image",SqlDbType.Image).Value = image;
cmd.ExecuteNonQuery();
}
}
Look up the various classes used (FileStream, SqlConnection, SqlCommand) in
MSDN for more info.
-cd