How to Save Images to Database and Shows Slide show for Current Date Image


Through-out the article we will learn learn step-by-step: How to Insert images to Database and Retrieve the Images Based on Current Date and showing the images with Slide shows following Images Source Given Below. I have mention code below for step by from Database side to C# coding side.

Abstract



Through-out the article we will learn step-by-step: HHow to Insert images to Database and Retrieve the Images Based on Current Date and showing the images with Slide shows in Dotnet Framework.

We will discuss How to Insert images to Database and Retrieve the Images Based on Current Date and showing the images with Slide shows in C#,Sql Server

Introduction


In these days, Dotnet framework is most growing framework and as a developer I am curious to know and learn about the new features of this framework.

From last couple of days I was wondering how can I perform How to Insert images to Database and Retrieve the Images Based on Current Date and showing the images with Slide shows in C#,Sql Server. For the same I have gone through various forums etc. Unfortunately, I did saw very few posts/articles for the same.

Finally, I tried and came with a solution to perform How to Insert images to Database and Retrieve the Images Based on Current Date and showing the images with Slide shows in C#,Sql Server. In this article, I am going to share my findings with all of you.

Why Step-by-Step



Ah! This question came to my mind while I was finding the solution of my problem, I jotted down few points and finally
called them as a steps to perform How to Insert images to Database and Retrieve the Images Based on Current Date and showing the images with Slide shows in C#,Sql Server.

Pre-requisite


To implement the solution and to feel the taste of code, you should:

  • Have Visual Studio 2013 or later with the support of Visual studio 2012

  • Have Basic Idea of SQL Server

  • Have Basic Idea of Sql queries



What we are waiting for?


So, what we are waiting for here, lets get started. Just following these step(s) and we will done!


How to Create Table for this scenario




CREATE TABLE ImgSlideshow
(
id INT PRIMARY KEY IDENTITY(1,1),
ename varchar(20),
Entrydate date,
saveimage varchar(200)
)


How to Create Procedure for this



CREATE PROCEDURE AddImgInfo
@Ename VARCHAR(40),
@saveimgpath varchar(150)
AS
BEGIN
insert into ImgSlideshow (Ename,Entrydate,saveimage)
values(@Ename,GETDATE(),@saveimgpath)
END





<h1>Image Insert</h1>

<table>
<tr>
<td>
Student Name
</td>
<td>
<asp:TextBox ID="TxtstudName" runat ="server"></asp:TextBox>
</td>
</tr>

<tr>
<td>
Upload Image
</td>
<td>
<asp:FileUpload ID="Fup1" runat ="server" />
</td>
</tr>

<tr>
<td colspan="2">
<asp:Button ID="BtSubmitImg" runat ="server" Text ="Submit" OnClick="BtSubmitImg_Click" />
<asp:Button ID="BtShowImage" runat ="server" Text ="Submit" OnClick="BtShowImage_Click" />
</td>
</tr>
</table>




How to Insert images to Database using C#




protected void BtSubmitImg_Click(object sender, EventArgs e)
{
Fup1.SaveAs(Server.MapPath("Images")+"\\"+Fup1.PostedFile.FileName);
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand("AddImgInfo", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Ename", SqlDbType.VarChar).Value = TxtstudName.Text;
cmd.Parameters.Add("@saveimgpath", SqlDbType.VarChar, 50).Value = Fup1.PostedFile.FileName;
con.Open();
int Result = cmd.ExecuteNonQuery();
con.Close();
}


How to Scrolling Images Depends on Current Date




protected void BtShowImage_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionstring);
DataTable dt = new DataTable();
con.Open();
SqlDataAdapter sqladp = new SqlDataAdapter("select * from ImgSlideshow where convert(char(10), Entrydate, 101) =CONVERT(VARCHAR, GETDATE(), 101) ", con);
sqladp.Fill(dt);
string SQRY = "<marquee direction=right behavior='alternate'><font color=blue>" + "<img src='" + "Images\\" + dt.DefaultView[0]["saveimage"] + "' width=100 height=100/></font></marquee>";
Response.Write(SQRY);
}



Date Format in Sql server




-- This is Date Format in sql server

1 101 1 = mm/dd/yy
2 102 2 = yy.mm.dd
3 103 3 = dd/mm/yy
4 104 4 = dd.mm.yy
5 105 5 = dd-mm-yy
6 106 6 = dd mon yy
7 107 7 = Mon dd, yy


Hope it will helpful to you.


Comments

Author: Nirav Lalan24 Jul 2015 Member Level: Gold   Points : 0

Hello,

Your image is not showing on BtShowImage_Click event. I think you should edit the article and set the image path properly.

Author: Dotnet Developer-201524 Jul 2015 Member Level: Gold   Points : 0

Hi
Nirav

Check this article My Code in the marquee tag Image Fetch from Database so we cant seen the Image.

Copy this code your pc and try and let me know.

Author: Gaurav Kumar Arora28 Jul 2015 Member Level: Gold   Points : 0

Hi,
I formatted the code and encoded script to make it available to view.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: