C:\1.jpg,你这个C:是服务器的绝对地址,还是客户浏览器端的地址。如果是前者只要把它当作文件打开,再以二进制保存到数据库就行了,如果是客户端的,那还要先上传。

解决方案 »

  1.   

    // 表搞那么麻烦,且你没有理解 FileMode FileAccess 两个枚举的意义,请查阅 MSDN
    // 
    FileStream fs = new FileStream(@"C:\1.jpg",FileMode.Open, FileAccess.Read);
    byte[] imgBuffer = new byte[fs.Length];
    fs.Read(imgBuffer, 0, fs.Length);//
    string sqlInsert = "INSERT tbl(ImageBuffer) VALUES(@ImageBuffer)";
    string myConnStr;
    // ...
    SqlConnection conn = new SqlConnection(myConnStr);
    SqlCommand cmd = conn.CreateCommand();
    cmd.CommandText = sqlInsert;
    cmd.Parameters.Add("@ImageBuffer", SqlDbType.Image).Value = imgBuffer; // 命令参数
    cmd.ExectueNonQuery();