Skip to content

Creating in asp.net Csharp

Nkululeko Mazibuko

Asked Sep 28, 2011, 3:09 AM EDT3 answers
Share
LinkedInX
Hi people!

Can anyone please help me on how I can go about creating a Slideshow with images loaded from an SQL database.
Here is my SQL Script for the table:

CREATE TABLE [dbo].[Pictures](
  [PicId] [uniqueidentifier] NOT NULL,
  [Picture] [image] NOT NULL,
  [PicDescription] [varchar](40) NULL,
  [DateAdded] [datetime] NOT NULL,
 GO

Here is the Procedure I created for what I think would be needed to return the images in asp
CREATE PROC GetAllPictures
AS
SELECT PicId, Picture
FROM Pictures

I hope I can get a responce from anyone this would realy help me for my project.

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    first of all.... ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead. Secondly if you want to use then...follow the steps below, 1) While saving convert your image into byte of array 2) While reading store the data into byte of array and display it.
    0
  • 0
    Can you please demonstrate the code for me if its not too much to ask for, thanks very much
    0
  • 0
    FileInfo fInfo = new FileInfo(sPath); long numBytes = fInfo.Length; FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fStream); //When you use BinaryReader, you need to supply number of bytes //to read from file. //In this case we want to read entire file. //So supplying total number of bytes. byte[] imageData = br.ReadBytes((int)numBytes); SqlConnection conn = new SqlConnection(txtConnectionString.Text); string qry = "insert into ImagesSt (ImageData) values( @ImageData)"; SqlCommand SqlCom = new SqlCommand(qry, conn); SqlCom.Parameters.Add(new SqlParameter("@ImageData", (object)imageData)); conn.Open(); SqlCom.ExecuteNonQuery(); CN.Close(); Reading............. SqlDataAdapter ad= new SqlDataAdapter("Select * from ImagesStore", conn); DataSet ds= new DataSet(); ad.Fill(DS, "ImagesStore"); //Fill Grid with dataset. dataGridView1.DataSource = ds.Tables["ImagesStore"];
    0