Sql server 如何在图像数据类型表中插入值

Sql server 如何在图像数据类型表中插入值,sql-server,sql-server-2012-express,Sql Server,Sql Server 2012 Express,我正在使用Sql Server 2012。在其中,我在Person表中创建了一个名为Image的列,其中包含数据类型Image。请解释我如何在其中增加价值?我的意思是我应该定义任何照片的路径吗?或者,是否有其他方法可以在此列中插入图像?期待您的指导 Person——表名 人名——数据类型为nvarchar(50)的列名 Image--数据类型为Image的列名 Date--数据类型为Date的列名 或插入类似于:` INSERT INTO Person Values ( 'Person34',

我正在使用Sql Server 2012。在其中,我在Person表中创建了一个名为Image的列,其中包含数据类型Image。请解释我如何在其中增加价值?我的意思是我应该定义任何照片的路径吗?或者,是否有其他方法可以在此列中插入图像?期待您的指导

Person——表名 人名——数据类型为nvarchar(50)的列名 Image--数据类型为Image的列名 Date--数据类型为Date的列名

或插入类似于:`

INSERT INTO Person  Values
( 'Person34', '  
SELECT  *  
       FROM OPENROWSET  
      ( BULK 'C:\Users\Public\Pictures\Sample Pictures\Lighthouse.jpg',SINGLE_CLOB)' , '2013-09-08');
`
谢谢。

这是我将图像保存在BLOB/image DB字段中的方法

/// <summary>
/// Saves the file into a BLOB/Image field in the DB
/// This uses an UPDATE command, therefore the record must alreay exist in the DB
/// </summary>
/// <param name="aTableName"></param>
/// <param name="aFieldName"></param>
/// <param name="aWhereClause"></param>
/// <param name="aFileName"></param>
/// <returns></returns>
public bool SaveToBLOB(string aTableName, string aFieldName, string aWhereClause, string aFileName)
{
  string sSQL = string.Format("UPDATE {0} SET {1}=@{1} WHERE {2}", aTableName, aFieldName, aWhereClause);
  using (SqlCommand oComm = new SqlCommand(sSQL, m_Conn))
  {
    byte[] wFileAsByteArr = CDBConn.GetFileAsByteArray(aFileName);

    oComm.Parameters.Add("@" + aFieldName, SqlDbType.Image, wFileAsByteArr.Length).Value = wFileAsByteArr;
    return oComm.ExecuteNonQuery() > 0;
  }
}

asql命令的位置:从TableABC中选择MyImageField,其中…

感谢您的分享,但我想在sql server 20102中执行查询。
        // Create a file to hold the output.
        using (System.IO.FileStream fs = new System.IO.FileStream(aFileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write))
        {
            using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs))
            {
                byte[] b = (byte[])oComm.ExecuteScalar();
                if (b != null)
                {
                    bw.Write(b);
                    bw.Flush();
                    return true;
                }
                else
                    return false;
            }
        }
    }
}