2014-06-22 2 views
-1

db에 이미지를 삽입하면 공백입니다. 당신이 코멘트에 링크에서 얻을 수없는 경우명령을 사용하여 이미지를 삽입하는 방법. 매개 변수

  string sql = "INSERT INTO tblProfile(EmployeeID,FirstName, MiddleName,LastName,Gender,Age,Email, DateofBirth,RFID,PlaceofBirth,MaritalStatus,SSS,TIN,PhilHealth, Mobile,City, HomeAddress, Nationality, Religion,ContactPerson,ContactNumber,Image)" + 
       "VALUES(@ID,@FirstName,@MiddleName,@LastName,@Gender,@Age,@Email,@DateofBirth,@RFID,@PlaceofBirth,@MaritalStatus,@SSS,@TIN,@PhilHealth, @Mobile,@City,@HomeAddress, @Nationality, @Religion,@ContactPerson,@ContactNumber,@IMG)"; 
      if (conn.State != ConnectionState.Open) 
       conn.Open(); 
      command = new SqlCommand(sql, conn); 

      command.Parameters.Add("@ContactNumber", SqlDbType.VarChar).Value = Convert.ToString(txtContactNumber_New.Text);            
      command.Parameters.Add(new SqlParameter("@IMG", img)); 
+0

지금까지 시도한 내용은 무엇입니까? – dotnetstep

+0

http://www.digitalcoding.com/Code-Snippets/C-Sharp/C-Code-Snippet-Insert-Update-Image-To-SQL-Server.html 더 많은 코드를 제공해주십시오. 당신의 img 객체 타입은 무엇입니까 – dotnetstep

+0

이미지 데이터 타입에 varbinary를 사용하고 있습니다. 나머지는 이미지 만 비어 있습니다. – user3733132

답변

0

당신이 일 다음을 수행해야합니다 :

내 코드입니다.

byte[] img = // Read you image as byte array. 
var _SqlParameter = new SqlParameter("@Img", SqlDbType.Image); 
_SqlParameter.Value = img; 
// In above line img should be by array. 

여기에 더 자세한 예제가 나와 있습니다. http://msdn.microsoft.com/en-us/library/4f5s1we0(v=vs.110).aspx

+0

link.It 작동 해 주셔서 감사합니다! – user3733132

관련 문제