Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8903963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:00:09+00:00 2026-06-15T02:00:09+00:00

I am trying to pull data from a Database using C#.net and use a

  • 0

I am trying to pull data from a Database using C#.net and use a Foreach loop to make it visible on a page. Every time i run the code i only get one item that shows up when i know that there is at least 7 items in the DB. i have placed the code below for the C#.

SqlConnection oConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["HomeGrownEnergyConnectionString"].ToString());
    string sqlEnergy = "Select * from Product p where p.ProductTypeId=3";
    SqlCommand oCmd = new SqlCommand(sqlEnergy, oConnection);
    DataTable dtenergy = new DataTable();
    SqlDataAdapter oDa = new SqlDataAdapter(oCmd);
    try
    {
        oConnection.Open(); ;
        oDa.Fill(dtenergy);
    }
    catch (Exception ex)
    {
        lblnodata.Text = ex.Message;
        return;
    }
    finally
    {
        oConnection.Close();
    }
    DataTableReader results = dtenergy.CreateDataReader();

    if (results.HasRows)
    {
        results.Read();
        foreach(DataRow result in dtenergy.Rows)
        {
            byte[] imgProd = result["ThumnailLocation"] as byte[];
            ID.Text = result["ProductID"].ToString();
            Name.Text = result["Name"].ToString();
            price.Text = FormatPriceColumn(result["Price"].ToString());


        }
    }

Here is the code for the asp.net.

<div>
<asp:Image ID="imgProd" CssClass="ProdImg" runat="server" />
<asp:Label runat="server" ID="ID"  />
<asp:Label runat="server" ID="Name" />
<asp:Label runat="server" ID="price" />
<asp:TextBox ID="txtQty" MaxLength="3" runat="server" Width="30px" />
<asp:Button runat="server" ID="Addtocart" Text="Add To Cart" CommandName="AddToCart" ItemStyle-CssClass="btnCol" />

If someone could please help me that would be great thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:00:11+00:00Added an answer on June 15, 2026 at 2:00 am

    You should set the image column type in database to byte[] and use this tow method to get and set the image:

    public BitmapImage ImageFromBuffer(Byte[] bytes)
    {
        MemoryStream stream = new MemoryStream(bytes);
        BitmapImage image = new BitmapImage();
        image.BeginInit();
        image.StreamSource = stream;
        image.EndInit();
        return image;
    }
    
    public Byte[] BufferFromImage(BitmapImage imageSource)
    {
        Stream stream = imageSource.StreamSource;
        Byte[] buffer = null;
        if (stream != null && stream.Length > 0)
            {
                using (BinaryReader br = new BinaryReader(stream))
                    {
                        buffer = br.ReadBytes((Int32)stream.Length);
                    }
            }
    
        return buffer;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pull data from my database using json in php. I have
I'm currently trying to pull data from a database using a variable and then
I am using jQuery and JSON to pull data from a database. Each row
I'm using C# to pull spatial data from a sql server 2008 database. I'm
I'm trying to pull some binary data from a database and write them to
I'm simply trying to get data from two sql server db tables using ado.net
Here's what I'm trying to do. I'm trying to pull data from a database
I am trying to pull data from our Oracle datamart into R using RODBC.
I am trying to pull invoice data from my database based on a PatientID.
I'm trying to pull data from the YouTube API into a local MySQL table.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.