Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,

Now i wanna to retrieve image from database and display that at picturebox.
I spend more time but an error occured "Parameter is not valid". Here how can i
overcome this error. All replies welcome.

Thanks in Advance
Dhinesh kumar.V

C#
private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = (@"Data Source=EUNIK-705F2C195\SQLEXPRESS;Initial Catalog=images;User ID=sa;Password=fintransys");
            con.Open();
                     
             SqlCommand _sqlcommand = new SqlCommand("select Images from imagestore where ImageID='" + txt_EnterID.Text + "'", con);
            SqlDataAdapter _sqldataadapter = new SqlDataAdapter(_sqlcommand);
            DataSet _dataset = new DataSet();
            DataTable _dataTable = new DataTable();
            _sqldataadapter.Fill(_dataset,"imagestore");
            int c = _dataset.Tables["imagestore"].Rows.Count;

            if(c>0)
            {
                Byte[] _Byte = new Byte[0];
                _Byte = (Byte[])(_dataset.Tables["imagestore"].Rows[c - 1]["Images"]);
                MemoryStream _Memorystream = new MemoryStream(_Byte);
                pictureBox1.Image = Image.FromStream(_Memorystream);
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBox1.Refresh();
            }
            con.Close();
        }



Here TableName-> imagestore ColumnName->Images

Enhzflep: code copied from comments to original question
Posted
Updated 30-Jul-12 3:39am
v2
Comments
Mehdi Gholam 30-Jul-12 5:51am    
Show your code.
Dhinesh kumar.V 30-Jul-12 9:07am    
Snip! 8<

Code removed from comments - posted 3 times! Pasted into original question.
-enhzflep
[no name] 30-Jul-12 9:25am    
Why on earth did you repost this 3 times instead of improving your "question"?
Santhosh Kumar Jayaraman 30-Jul-12 5:58am    
agree. show us ur code and let us know where u got error?
enhzflep 30-Jul-12 8:29am    
By either/both of the following:
1) Make the parameter valid
2) Show the offending code so that someone else can do (1)

1 solution

Does this[^] or this[^] help?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900