프로젝트 (Winforms 및 웹 서비스 프로젝트)에 각각 데이터베이스가 두 개 있으며 프로젝트 1에서 프로젝트 2로 데이터를 전송하는 Entity Framework를 사용하는 쿼리가 있습니다. 어떻게하면 첫 번째 데이터베이스의 이미지를 문자열을 쿼리를 통해 보낼 수 있습니까?SQL Server에서 이미지를 문자열로 변환하는 방법은 무엇입니까?
이 내 웹 서비스 코드 :
// Entity Framework
Person sd = new Person();
// Method to get data from winforms app
public void GetData(string name,string picture)
{
sd.name= name;
sd.picture= ImageToByteArray(picture);
context.AddToPerson(sd);
context.SaveChanges();
}
//Method to save the image into database
private Byte[] ImageToByteArray(string source)
{
FileInfo fInfo = new FileInfo(source);
long sizeByte = fInfo.Length;
FileStream fs = new FileStream(source, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] data = br.ReadBytes((int)sizeByte);
return data;
}
그리고 이것은 내 윈폼 코드입니다 : 내가 문자열로 이미지를 누군가 그렇다면하시기 바랍니다 변환하는 방법을 필요로하는 경우
WebService3SD.Service1SoapClient oService = new WebService3SD.Service1SoapClient();
private void SendData()
{
Driver dr = context.Drivers.FirstOrDefault(d => d.name == "name1");
oService.GetData(dr.name,????);//here i have no idea what i have to do ?!
}
내가 그것에 대해 매우 높이 평가하게 될 것이라고 생각하는 어떤 있습니다.
그것은 분명를'GetData' *이'picture' 문자열이 될 것으로 예상 서버 *의 파일 경로를 나타냅니다. (그것은'FileInfo'의 생성자에 전달됩니다.) 그래서 "이미지를 문자열로 변환"하는 것이 아니라 이미 서버에있는 파일에 경로를 전달해야합니다. 이것이 원하는 것이 아니면 로컬 경로를 기반으로 작동하지 않도록 서버를 구현해야합니다. –
좋은 솔루션이 될 것 ** Kirk **하지만 어떻게 코딩 할 수 있습니까? – Mohammadov