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
Marvin kakuru
1.4k
355
160.1k
Image
Mar 10 2012 4:24 PM
hi everyone,
i have been trying to display an image selected from my sql database in a picturebox.below is the code im using
SqlConnection cn = new SqlConnection("Data Source=KATOTO-PC;Initial Catalog =AssetRegister;User ID=sa;Password=Kyozi");
string sql = ("select serialnumber,supplier,assetimage from AssetInformation where serialnumber like '" + textBox1.Text + "'");
SqlCommand cmd = new SqlCommand(sql, cn);
cn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read(); // read first row
textBox2.Text = sdr[2].ToString(); // read first column
if (sdr.HasRows)
{
while (sdr.Read())
{
byte[] getimage = (byte[])sdr[2];
MemoryStream ms = new MemoryStream(getimage);
Image myimage = Image.FromStream(ms);
pictureBox2.Image = myimage;
}
sdr.Close();
}
however nothing is displayed in my picturebox,but if i change line "
textBox2.Text = sdr[2].ToString(); // read first column"
to
sdr[2]
which is the column of my image, it brings "System.Byte[]"
any help.
best regards.
Reply
Answers (
5
)
Printing sql query result into text file
Resource file serialization error