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
Ramu Eppakayala
NA
25
2.3k
retreive bitmap image from database.
Feb 20 2020 2:35 AM
i am performing search operation and retreiving image from database to pictureEdit control. I stored image as varchar(4000). and images are storing in the format of System.Drawing.Bitmap.I am getting Error as -> "Unable to cast object of type 'System.String' to type 'System.Byte[]".
private
void
btnSearch_Click(
object
sender, EventArgs e)
{
byte
[] getImg =
new
byte
[0];
SqlDataAdapter dataAdapter =
new
SqlDataAdapter(
"select sid,sname,fathername,contactno,address,sphoto from Student where sclass='"
+ lukupClass.Text +
"' and ssection='"
+ lukupSection.Text +
"' and sname='"
+ textBox1.Text +
"'"
, sqlConnection);
DataTable dt =
new
DataTable();
dataAdapter.Fill(dt);
if
(dt.Rows.Count > 0)
{
txtID.Text = dt.Rows[0][
"sid"
].ToString();
txtStudentName.Text = dt.Rows[0][
"sname"
].ToString();
txtFatherName.Text = dt.Rows[0][
"fathername"
].ToString();
txtContactNo.Text = dt.Rows[0][
"contactno"
].ToString();
memoAddress.Text = dt.Rows[0][
"address"
].ToString();
getImg = ((
byte
[])dt.Rows[0][
"sphoto"
]);
byte
[] imgData = getImg;
MemoryStream stream =
new
MemoryStream(imgData);
picStudent.Image = Image.FromStream(
new
MemoryStream(getImg));
}
else
{
MessageBox.Show(
"No Data Found with this Name."
);
}
Reply
Answers (
7
)
SqlDataAdapter for Inserting and Deleting records in DB
which is better asp.net mvc , asp.net core or asp.net blazer