日期:2014-05-18  浏览次数:21049 次

通过SQL语句如何向image字段更新
SQL code
UPDATE YX_TASK_ATTACH
SET    TASK_CD = 'EML',
       SCHEDULELDID = 'TASK257',
       IMG_EDM = 'System.Byte[]',
       ↑↑↑↑↑↑↑↑↑↑↑↑↑ ※IMG_EDM是image类型
       UPDATE_DT = '2011-12-26 16:56:22'
WHERE SCHEDULELDID = 'TASK257'


请问以上如何更新

------解决方案--------------------
将IMG_EDM用文件流的方式读取出来,然后用updateblob 的方式更新image类型的字段.
------解决方案--------------------
给我我用的:
C# code

    img = Image.FromFile(@"c:\test.jpg");
    MemoryStream ms = new MemoryStream();
    img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    byte[] myData = ms.ToArray();

    SqlConnection cn = new SqlConnection("Data Source=(local);Initial Catalog=utscadadb;Integrated Security=SSPI; User Id=sa;Password=ut2001;");
    SqlCommand cmd = new SqlCommand("Update Table1 Set file=(@file),data = (@data) where id =3", cn);

    cmd.Parameters.Add("@file ", SqlDbType.VarChar).Value = "d:\\test.jpg";
    cmd.Parameters.Add("@data ", SqlDbType.Image).Value = myData;

    cn.Open();
    cmd.ExecuteNonQuery();
    cn.Close();