• Here is a PowerShell example:

    #env settings

    $srv = "orlando-surface\sql2012"

    $db = "tempdb"

    $dir = "C:\@\"

    #########################################################################

    #nothing below here changes

    #build connection string

    $connStr = "Server=$srv;Database=$db;Trusted_Connection=True;"

    #connect to the database

    $conn = New-Object System.Data.SqlClient.SqlConnection($connStr)

    $conn.Open()

    #get list of files from directory

    foreach($file in (Get-ChildItem $dir | where {-not $_.PSIsContainer}))

    {

    $filename = $file.FullName

    $name = $file.Name

    $binData = [System.IO.File]::ReadAllBytes($filename)

    #prepare

    $cmd = New-Object System.Data.SqlClient.SqlCommand("Insert into images (image_name, image_data) values(@image_name, @image_data)", $conn)

    $cmd.CommandType = [System.Data.CommandType]'Text'

    $cmd.Parameters.Add("@image_name", [System.Data.SqlDbType]'VarChar')

    $cmd.Parameters["@image_name"].Value = $name

    $cmd.Parameters.Add("@image_data", [System.Data.SqlDbType]'VarBinary')

    $cmd.Parameters["@image_data"].Value = $binData

    #execute

    $cmd.ExecuteNonQuery()

    }

    $conn.Close()

    $conn.Dispose()

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato