Jes Sie

Jes Sie

  • 704
  • 1.2k
  • 265.2k

casting byte[] in c#

Aug 16 2018 10:47 PM
I need to insert to database a varbinary type. In my code behind, I created a method which will insert the data.:
  1. private void insertAudioFiles()  
  2.         {  
  3.             ResourcesAudioDataModel audio = new ResourcesAudioDataModel();  
  4.             ResourceDataAccess insert = new ResourceDataAccess();  
  5.             using(BinaryReader br = new BinaryReader(FileUpload2.PostedFile.InputStream))  
  6.             {  
  7.                 string GL = lblGrLvlId.Text;  
  8.                 string sub = ddlSubject.SelectedValue;  
  9.                 string week = ddlWeekNo.SelectedValue;  
  10.                 string teacher = lblID.Text;  
  11.                 string type = Path.GetFileName(FileUpload2.PostedFile.FileName);  
  12.                 byte[] bytes = br.ReadBytes((int)FileUpload2.PostedFile.InputStream.Length);  
  13.   
  14.                 audio.GradeLevelId = Convert.ToInt32(gl.ToString());  
  15.                 audio.SubjectId = Convert.ToInt32(sub.ToString());  
  16.                 audio.WeekNo = week.ToString();  
  17.                 audio.TeacherId = Convert.ToInt32(lblID.ToString());  
  18.                 audio.ContentType = type.ToString();  
  19.                 audio.Data = Convert.ToInt32(bytes);  
  20.             }  
  21.               
  22.         }  
 I have an error in line 19 (audio.Data = Convert.ToInt32(bytes);). Tried to changed it to audio.Data = Convert.ToByte[](bytes); but still no luck. Can anyone share your knowledge? Thanks a lot.

Answers (1)