TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jes Sie
744
1.2k
284.7k
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.:
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.
Reply
Answers (
1
)
Sum of duplicated items Tuple C#
Upload Word File and read the fields