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
Faisal Ansari
NA
451
833.6k
how to retrieve image from data base ?
Jul 27 2012 2:53 AM
hello guys how r u ?
i want to retrieve image in picture box from database on datagridview cell click event .
but exception raising like "parameter is not valid"
code below here
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
Image image;
int id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["ID"].Value);
SqlConnection con = new SqlConnection(@"Data Source=ITOFASL254\SQLEXPRESS; Initial Catalog=TestDB; Integrated Security=SSPI; user id=sa; password=passpass; Trusted_Connection=False; database=TestDB;");
con.Open();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("select Image from ImageStore where ID=" + dataGridView1.Rows[e.RowIndex].Cells["ID"].Value, con);
DataSet ds = new DataSet();
adapter.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
byte[] imageData = (byte[])ds.Tables[0].Rows[0][0];
using (MemoryStream ms = new MemoryStream(imageData, 0, imageData.Length))
{
ms.Write(imageData, 0, imageData.Length);
image = Image.FromStream(ms);
}
pictureBox1.Image = image;
}
con.Close();
}
Reply soon
Reply
Answers (
5
)
Hosting of Windows Form Application on Web
Error while saving image to database using winform c#?