I need to insert to database a varbinary type. In my code behind, I created a method which will insert the data.:
- private void insertAudioFiles()
- {
- ResourcesAudioDataModel audio = new ResourcesAudioDataModel();
- ResourceDataAccess insert = new ResourceDataAccess();
- using(BinaryReader br = new BinaryReader(FileUpload2.PostedFile.InputStream))
- {
- string GL = lblGrLvlId.Text;
- string sub = ddlSubject.SelectedValue;
- string week = ddlWeekNo.SelectedValue;
- string teacher = lblID.Text;
- string type = Path.GetFileName(FileUpload2.PostedFile.FileName);
- byte[] bytes = br.ReadBytes((int)FileUpload2.PostedFile.InputStream.Length);
-
- audio.GradeLevelId = Convert.ToInt32(gl.ToString());
- audio.SubjectId = Convert.ToInt32(sub.ToString());
- audio.WeekNo = week.ToString();
- audio.TeacherId = Convert.ToInt32(lblID.ToString());
- audio.ContentType = type.ToString();
- audio.Data = Convert.ToInt32(bytes);
- }
-
- }
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.