filmov
tv
Load image from database in asp net

Показать описание
Text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
All ASP .NET Text Articles
All ASP .NET Slides
ASP.NET Playlist
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
Tags
c# load image from sql database
Step 1 : Create stored procedure to retrieve image by Id.
Create procedure spGetImageById
@Id int
as
Begin
Select ImageData
End
Go
<asp:Image ID="Image1" Height="500px" Width="500px" runat="server" />
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace Demo
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("spGetImageById", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramId = new SqlParameter()
{
Value = Request.QueryString["Id"]
};
cmd.Parameters.Add(paramId);
con.Open();
byte[] bytes = (byte[])cmd.ExecuteScalar();
string strBase64 = Convert.ToBase64String(bytes);
Image1.ImageUrl = "data:Image/png;base64," + strBase64;
}
}
}
}
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
All ASP .NET Text Articles
All ASP .NET Slides
ASP.NET Playlist
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
Tags
c# load image from sql database
Step 1 : Create stored procedure to retrieve image by Id.
Create procedure spGetImageById
@Id int
as
Begin
Select ImageData
End
Go
<asp:Image ID="Image1" Height="500px" Width="500px" runat="server" />
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace Demo
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("spGetImageById", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramId = new SqlParameter()
{
Value = Request.QueryString["Id"]
};
cmd.Parameters.Add(paramId);
con.Open();
byte[] bytes = (byte[])cmd.ExecuteScalar();
string strBase64 = Convert.ToBase64String(bytes);
Image1.ImageUrl = "data:Image/png;base64," + strBase64;
}
}
}
}
Комментарии