나는 SQL 서버에서 이미지를 삽입하는 코드를 작성했습니다하지만 예외가 발생합니다 :SQL Server에서 이미지를 삽입하고 검색하는 방법은 무엇입니까?
문자열이나 이진 데이터는 잘립니다 것입니다. 그 진술서는 만료되었습니다. 여기
삽입 이미지 내 코드입니다 :
FileStream imageStream = new FileStream(CvVariables.IMAGE_PATH, FileMode.Open, FileAccess.Read);
int fileLangth = (int)imageStream.Length;
byte[] imageInBytes = new byte[fileLangth];
imageStream.Read(imageInBytes, 0, (int)fileLangth);
Cv_Customer_Information addNewCustomer = new Cv_Customer_Information
{
UserID = this.NewCustomerTextUserName.Text,
UserImage =new System.Data.Linq.Binary(imageInBytes),
Date = this.NewCustomerDate.SelectedDate.ToString(),
Name = this.NewCustomerTextBoxName.Text,
Phone = this.NewCustomerTextBoxPhone.Text,
Email = this.NewCustomerTextBoxEmail.Text,
NationalID = this.NewCustomerTextBoxNationalID.Text,
Address = this.NewCustomerTextBoxAddress.Text
};
singupDataContext.Cv_Customer_Informations.InsertOnSubmit(addNewCustomer);
singupDataContext.SubmitChanges();
나는 또한 SQL 서버에서 이미지를 검색하는 방법을 이해 돈`t은?
업데이트 : 나는 UserImage 필드에 이미지 데이터 형식을 사용하고 난 WPF
첫 번째 질문 - "문자열 또는 이진 데이터가 잘립니다.이 문은 종료되었습니다." 즉, 열이 데이터에 충분하지 않을 수도 있습니다. nvarchar (n)을 최대 값으로 변경해야합니다. –
SQL Server 2008 R2를 사용하는 경우 (이 질문의 태그에서 제안한 것처럼) NVARCHAR (MAX)] (http://msdn.microsoft.com/en-us/library/ms186939.aspx) 열 [최대 2GB 허용] (http://msdn.microsoft.com/en-us/ 라이브러리/ms176089.aspx)에 저장해야합니다. – CraigTP
이것은 이상한 제안입니다. 문자 데이터가 아니며 이진 데이터입니다. Nvarchar (아무것도) 그냥 잘못되었습니다. 이것에 대한 '이미지'유형 - 또는 varbinary 또는 파일 스트림이 디스크에 저장되어있는 경우. nvarchar 이외의 문자 –