Click here to Skip to main content
16,010,114 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
SqlConnection con = new SqlConnection();
        con.ConnectionString = "Data Source=PROMOD-PC;Initial Catalog=travel_Directions;Integrated Security=True";


        DataTable dt = new DataTable();

        String selQuery = "SELECT Image FROM MapDataImage WHERE Source='" + TextBox1.Text + "';";

        SqlCommand SelCmmnd = new SqlCommand(selQuery);
        SqlDataAdapter sDatAdp = new SqlDataAdapter();
        SelCmmnd.CommandType = CommandType.Text;
        SelCmmnd.Connection = con;

        con.Open();

        SqlDataReader dr = SelCmmnd.ExecuteReader();
        dr.Read();
        Context.Response.BinaryWrite((byte[])dr["Image"]);
        Context.Response.ContentType = "image/jpg";

        

        sDatAdp.SelectCommand = SelCmmnd;


        //sDatAdp.Fill(dr);

        ListView1.DataSource = dr;
        ListView1.DataBind();

        con.Close();
        dr.Close();
        sDatAdp.Dispose();
        con.Dispose();
        dt.Dispose();
       }


now code is working.... bu thing is when i clicked the button it goes to another page and view the image...
......
i have given a specific area to view the image in my page.
but when i cliked the buuton it views in new page.
Posted
Updated 4-Jul-13 15:44pm
v10
Comments
Sushil Mate 4-Jul-13 5:56am    
This is not good question, What error you are facing? Can't you just put breakpoint & debug it.
promod madushan 4-Jul-13 6:03am    
Error -

Both DataSource and DataSourceID are defined on 'ListView1'. Remove one definition.
Richard MacCutchan 4-Jul-13 6:07am    
You were given the option of removing one of two items, and you chose to remove something else instead. Why?
promod madushan 4-Jul-13 7:49am    
you mean do i have to remove client side DataSource or DataSourceID
promod madushan 4-Jul-13 7:58am    
Image: System.Byte[] guys now code is ready... but when i clicked the button... it will show label like Image: System.Byte[]....
is there any problem in the code?

try this...:)


ImageListView[^]
 
Share this answer
 
Comments
promod madushan 4-Jul-13 10:02am    
can't i add converting to bytes method in middle of the code...?
Nirav Prabtani 4-Jul-13 10:06am    
Can you describe exact position??
promod madushan 4-Jul-13 10:16am    
in my code?
cant i replace
byte[] photoarray = ((byte[])dt."@Image");
this like a code?

this code is made by me. but it's not working
promod madushan 4-Jul-13 10:18am    
@Nirav

can't i use that kind of a code after sDatAdp.Fill(dt); this code...
can't i convert this dt into bytes and display it in ListView
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=PROMOD-PC;Initial Catalog=travel_Directions;Integrated Security=True";
String selQuery = "SELECT Image FROM MapDataImage WHERE Source='" + TextBox1.Text + "';";
SqlCommand SelCmmnd = new SqlCommand(selQuery, con);
SqlDataReader mysrdr = new SqlDataReader();
//DataTable dt = new DataTable();

con.Open();

mysrdr = SelCmmnd.ExecuteReader();

byte[] myimg = (byte[])(mysrdr["image"]);
MemoryStream memstr = new MemoryStream(myimg);
pictureBox1.Image = System.Drawing.Image.FromStream(memstr);
C#




Here, can't we add ListView1 instead PitureBox1....
 
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