jasonbrandt3
asked on
Help displaying images pulled from Sql Server into Web Applicatoin
I've created a store front. I am able to view everything in my loop I'm attaching except the images will not display. Here is the database code, the images are stored in the varbinary(max) columns named Images of part etc.
CREATE TABLE [dbo].[Inventory_Table](
[Row_Index] [int] NULL,
[Part_Name] [char](50) NULL,
[Brand_of_Part] [char](15) NULL,
[Year_of_Part] [int] NULL,
[Price] [money] NULL,
[Type_of_Part] [char](15) NULL,
[Condition] [char](15) NULL,
[Images_of_Part] [varbinary](max) NULL,
[Images_of_Part_2] [varbinary](max) NULL,
[Images_of_Part_3] [varbinary](max) NULL,
[Images_of_Part_4] [varbinary](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
I've created a connector and everything comes through fine on the page except the images and I can't seem to understand why. Here is my code to pull the images, any assistance is very welcome!
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = ("Data Source=localhost\\test;Ini tial Catalog=Store Inventory;User ID = dbaStore;" + "Password = test;");
SqlConnection dbConnection = new SqlConnection(connectionSt ring);
string query = "SELECT * FROM INVENTORY_TABLE";
dbConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(query, dbConnection);
DataSet dsStore = new DataSet();
DataTable dtInventory = new DataTable();
adapter.FillSchema(dsStore , SchemaType.Source, "Inventory_Table");
adapter.Fill(dsStore, "Inventory_Table");
dtInventory = dsStore.Tables["Inventory_ Table"];
foreach (DataRow row in dtInventory.Rows)
{
itemList.Add(new Item());
foreach (DataColumn column in dtInventory.Columns)
{
itemList[dtInventory.Rows. IndexOf(ro w)].RowInd ex = Convert.ToInt32(row.ItemAr ray[0]);
itemList[dtInventory.Rows. IndexOf(ro w)].NameOf Part = Convert.ToString(row.ItemA rray[1]);
itemList[dtInventory.Rows. IndexOf(ro w)].BrandO fPart = Convert.ToString(row.ItemA rray[2]);
itemList[dtInventory.Rows. IndexOf(ro w)].YearOf Part = Convert.ToInt32(row.ItemAr ray[3]);
itemList[dtInventory.Rows. IndexOf(ro w)].Price = Convert.ToDecimal(row.Item Array[4]);
itemList[dtInventory.Rows. IndexOf(ro w)].TypeOf Part = Convert.ToString(row.ItemA rray[5]);
itemList[dtInventory.Rows. IndexOf(ro w)].Condit ion = Convert.ToString(row.ItemA rray[6]);
itemList[dtInventory.Rows. IndexOf(ro w)].Data_1 = (Byte[])(row.ItemArray[7]) ;
itemList[dtInventory.Rows. IndexOf(ro w)].Data_2 = (Byte[])(row.ItemArray[8]) ;
//Add images that are null
}
}
CREATE TABLE [dbo].[Inventory_Table](
[Row_Index] [int] NULL,
[Part_Name] [char](50) NULL,
[Brand_of_Part] [char](15) NULL,
[Year_of_Part] [int] NULL,
[Price] [money] NULL,
[Type_of_Part] [char](15) NULL,
[Condition] [char](15) NULL,
[Images_of_Part] [varbinary](max) NULL,
[Images_of_Part_2] [varbinary](max) NULL,
[Images_of_Part_3] [varbinary](max) NULL,
[Images_of_Part_4] [varbinary](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
I've created a connector and everything comes through fine on the page except the images and I can't seem to understand why. Here is my code to pull the images, any assistance is very welcome!
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = ("Data Source=localhost\\test;Ini
SqlConnection dbConnection = new SqlConnection(connectionSt
string query = "SELECT * FROM INVENTORY_TABLE";
dbConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(query, dbConnection);
DataSet dsStore = new DataSet();
DataTable dtInventory = new DataTable();
adapter.FillSchema(dsStore
adapter.Fill(dsStore, "Inventory_Table");
dtInventory = dsStore.Tables["Inventory_
foreach (DataRow row in dtInventory.Rows)
{
itemList.Add(new Item());
foreach (DataColumn column in dtInventory.Columns)
{
itemList[dtInventory.Rows.
itemList[dtInventory.Rows.
itemList[dtInventory.Rows.
itemList[dtInventory.Rows.
itemList[dtInventory.Rows.
itemList[dtInventory.Rows.
itemList[dtInventory.Rows.
itemList[dtInventory.Rows.
itemList[dtInventory.Rows.
//Add images that are null
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To store image into SQL server(C#):
Open in new window
To read it(C#):Open in new window