تقييمات الطلاب
( 5 من 5 )
١ تقييمات
فيديو شرح Save image to database using asp net ضمن كورس ASP.net شرح قناة kudvenkat، الفديو رقم 169 مجانى معتمد اونلاين
Text version of the video
http://csharp-video-tutorials.blogspot.com/2015/08/save-image-to-database-using-aspnet.html
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.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation1
Slides
http://csharp-video-tutorials.blogspot.com/2015/08/save-image-to-database-using-aspnet_11.html
All ASP .NET Text Articles
http://csharp-video-tutorials.blogspot.com/p/free-aspnet-video-tutorial.html
All ASP .NET Slides
http://csharp-video-tutorials.blogspot.com/p/aspnet-slides.html
ASP.NET Playlist
https://www.youtube.com/playlist?listPL4cyC4G0M1RQcB4IYS_zwkyBwMyx5AnDM
All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view1&sortdd
All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists
Tags
how to upload image in database table
sql server save image to database c#
how to save image to sql server database using c#
In this video we will discuss how to save images to database table using asp.net and c#.
In this video we will discuss how to upload the image to the database. In our next video we will discuss how to download the image from the database and display it on the web page.
Create table tblImages. This table stores the uploaded images along with it's name and size in bytes.
Create table tblImages
(
Id int primary key identity,
Name nvarchar(255),
Size int,
ImageData varbinary(max)
)
Go
Step 7 : Copy and paste the following code in WebForm1.aspx.cs
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblMessage.Visible false;
hyperlink.Visible false;
}
}
protected void btnUpload_Click(object sender, EventArgs e)
{
HttpPostedFile postedFile FileUpload1.PostedFile;
string filename Path.GetFileName(postedFile.FileName);
string fileExtension Path.GetExtension(filename);
int fileSize postedFile.ContentLength;
if (fileExtension.ToLower() ".jpg" fileExtension.ToLower() ".gif"
fileExtension.ToLower() ".png" fileExtension.ToLower() ".bmp")
{
Stream stream postedFile.InputStream;
BinaryReader binaryReader new BinaryReader(stream);
Byte[] bytes binaryReader.ReadBytes((int)stream.Length);
string cs ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con new SqlConnection(cs))
{
SqlCommand cmd new SqlCommand("spUploadImage", con);
cmd.CommandType CommandType.StoredProcedure;
SqlParameter paramName new SqlParameter()
{
ParameterName @"Name",
Value filename
};
cmd.Parameters.Add(paramName);
SqlParameter paramSize new SqlParameter()
{
ParameterName "@Size",
Value fileSize
};
cmd.Parameters.Add(paramSize);
SqlParameter paramImageData new SqlParameter()
{
ParameterName "@ImageData",
Value bytes
};
cmd.Parameters.Add(paramImageData);
SqlParameter paramNewId new SqlParameter()
{
ParameterName "@NewId",
Value -1,
Direction ParameterDirection.Output
};
cmd.Parameters.Add(paramNewId);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
lblMessage.Visible true;
lblMessage.ForeColor System.Drawing.Color.Green;
lblMessage.Text "Upload Successful";
hyperlink.Visible true;
hyperlink.NavigateUrl "~/WebForm2.aspx?Id" +
cmd.Parameters["@NewId"].Value.ToString();
}
}
else
{
lblMessage.Visible true;
lblMessage.ForeColor System.Drawing.Color.Red;
lblMessage.Text "Only images (.jpg, .png, .gif and .bmp) can be uploaded";
hyperlink.Visible false;
}
}
}
In our next video we will discuss how to download an image from the database and display it on the web page.