c# - Datareader not reading image value -


I am using Detector on page load to load the data and am storing the database value in my value , My table includes both narrative and image type columns. The value of my 5 images in the database on the page is not read by the reader, but others are completely read out.

  byte [] img1 = null; Byte [] img2 = null; Byte [] img3 = null; Byte [] img4 = null; Byte [] img5 = null; SqlConnection con = New SqlConnection ("Data Source = RAJ-PC \\ SQLEXPRESS; Initial Catalog = Finder; Integrated Security = True"); Protected Zero Page_load (object sender, event, aRGS e) {if (! Page. ISPostback) {load (); }} Secure Zero Load () {SqlCommand CMD = New SQL Commands ("sps_addetails", con); Cmd.CommandType = CommandType.StoredProcedure; Cmd.Parameters.AddWithValue ("@ ad_id", ad_id); Cmd.Parameters.AddWithValue ("useremail", SES); Con.Open (); SqlDataReader Reader = cmd.ExecuteReader (); While (reader.Read ()) {rd_iam.SelectedValue = reader ["iam"] ToString (); dd_category.SelectedValue = reader ["Category"] ToString (); C = Convert. ToInt16 (Reader ["Square"]. ToString ()); Dd_subcategory.SelectedValue = reader ["subcategory"] ToString (); Txt_title.Text = Reader ["Title"]. ToString (); Txt_description.Text = Reader ["Description"]. ToString (); Txt_pername.Text = Reader ["Contact Name"]. ToString (); txt_mobile1.Text = Reader ["mobile1"]. ToString (); txt_mobile2.Text = Reader ["mobile2"]. ToString (); txt_landline1.Text = Reader ["Landline 1"]. ToString (); txt_landline2.Text = Reader ["Landline 2"]. ToString (); txt_email1.Text = Reader ["email1"] ToString (); txt_email2.Text = Reader ["email2"]. ToString (); Txt_website.Text = Reader ["Website"]. ToString (); Dd_country.Text = Reader ["Country"]. ToString (); D = Convert. ToInt16 (Reader ["Country"]. ToString ()); Dd_state.Text = Reader ["State"]. ToString (); txt_pincode.Text = Reader ["Pincode"]. Toasting (); txt_address.txt = Reader ["Address"]. ToString (); Txt_lat.Text = Reader ["Latitude"] ToString (); txt_lon.Text = Reader ["Longitude"]. ToString (); img1 = (byte []) reader ["image1"]; img2 = (byte []) reader ["image2"]; Img3 = (byte []) reader ["image3"]; Img4 = (byte []) reader ["image4"]; img5 = (byte []) reader ["image5"]; } Con.Close (); }   

and the stored procedure is sps_add details

  alternate process [dbo]. [Sps_addetails] @ad_id int, @seeremail nvarchar (100) AS BEGIN Select * dbo.tbl_adregister from where useremail = @ useremail and ad_id = @ ad_id END   

aspx

  & amp; asp: FileUpload id = "FileUpload1" runat = "server" />   

The update button is the functionality (aspx.cs)

  byte [] imgbytes1 = null; If (FileUpload1.HasFile) {HttpPostedFile file1 = FileUpload1.PostedFile; Imgbytes1 = new byte [file1.ContentLength]; file1.InputStream.Read (imgbytes1, 0, file1.ContentLength); } And {imgbytes1 = img1; } Con.Open (); SqlCommand CMD = New SQL Commands ("sps_uploadphoto", Con?); Cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue ("@ imagedata1", imgbytes1); Cmd.ExecuteNonQuery (); Con.Close ();    

First try to determine the size of the image, then instantize the variable, and Then GetBytes () method:

  int index = ReaderGetordinal ("image1"); Int64 size = 0; Try {Size = reader.GetBytes (index, 0, blank, 0, int.MaxValue); } Hold {size = reader.getBytes (index, 0, IMG1, 0, 1); } Img1 = new byte [size]; Reader Getbytes (Index, 0, IMG1, 0, IMG 1. Lang); ... Rinse and repeat for 2 to 5 images ...   

Let us know if this is for you.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -