는
// **** Read File/Image into Byte Array from Filesystem
public static byte[] GetPhoto(string filePath)
{
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] photo = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
return photo;
}
이 그런 기능 위의 호출이 데이터베이스
// **** Read Image from Filesystem and add it to the Database.
public void AddFileDataIntoDatabase(
string a,string b,string c, string photoFilePath)
{
// Read Image into Byte Array from Filesystem
byte[] photo = GetPhoto(photoFilePath);
// Construct INSERT Command
SqlCommand addEmp = new SqlCommand(
"INSERT INTO tablename ("+
"col1,col2,Col3,Photo) "+
"VALUES(@col1,@col2,@col3,@Photo)",_conn);
addEmp.Parameters.Add("@col1", SqlDbType.NVarChar, 20).Value = plastName;
addEmp.Parameters.Add("@col2", SqlDbType.NVarChar, 10).Value = pfirstName;
addEmp.Parameters.Add("@col3", SqlDbType.NVarChar, 30).Value = ptitle;
addEmp.Parameters.Add("@Photo", SqlDbType.Image, photo.Length).Value = photo;
// Open the Connection and INSERT the BLOB into the Database
_conn.Open();
addEmp.ExecuteNonQuery();
_conn.Close();
}
Refer here
사용 VARBINARY 데이터 유형에 추가하십시오. 이 링크를 확인하십시오 : http://www.codeproject.com/Articles/468198/Store-Images-in-SQL-Server –