You must Sign In to post a response.
  • Category: .NET

    How to load images from database related to system day and month

    hi all
    i have completed the task successfully but only one problem where i am wrong i am not knowing

    actually i have written code for imageslideshow related to month and day so images are coming from database and sliding related to month and day so this project will run continuosly in system after executing
    so if system date changes then the date on which i executed only running still date is changing in system the images related to that date are not sliding
    so when i refresh the bowser or stop and debug application again then images coming related to system day and month
    finally what i want is actually system date will change every day sowhen sys date changes automatically images coming from database also change not like again refreshing or stopping and debugging application
    below is my code any bode suggest me where i am wrong


    public partial class separate : System.Web.UI.Page
    {
    static DataTable dt;
    static int TotalRecords, CurrentRecord;
    protected void Page_Load(object sender, EventArgs e)
    {




    //Repeater1.DataSource =GetEvents();
    ////Repeater1.DataBind();
    if (!Page.IsPostBack == true)
    {

    string sqlconstr = "Data Source=HOME;Initial Catalog=Registration;Integrated Security=True";
    SqlConnection con = new SqlConnection(sqlconstr);
    SqlDataAdapter sqlda = new SqlDataAdapter("select * from imagepath where CurrentDate is NULL union ALL SELECT * FROM imagepath WHERE month(CurrentDate) =month(CURRENT_TIMESTAMP)And day(CurrentDate) = day(CURRENT_TIMESTAMP)", con);
    //SqlDataAdapter sqlda = new SqlDataAdapter("select * from imagepath where CurrentDate is NULL union ALL select * from imagepath where convert(varchar(20), CurrentDate,101) = convert(varchar(20),getdate, 101)", con);
    dt = new DataTable();
    sqlda.Fill(dt);
    TotalRecords = dt.Rows.Count;
    Image1.ImageUrl = "~/Upload/" + dt.Rows[0]["ImageName"].ToString();

    //Response.Redirect("uploadsite.aspx");
    //SqlDataAdapter da1 = new SqlDataAdapter("select ImageName from imagepath where convert(varchar(20), CurrentDate, 101) = convert(varchar(20), getdate(), 101)", sqlconstr);
    DataSet ds1 = new DataSet();
    SqlDataAdapter da1 = new SqlDataAdapter("select ImageName from imagepath WHERE month(CurrentDate) =month(CURRENT_TIMESTAMP)And day(CurrentDate) = day(CURRENT_TIMESTAMP)", sqlconstr);
    da1.Fill(ds1, "imagepath");


    string s1 = string.Empty;

    if (ds1.Tables["imagepath"].Rows.Count > 0)
    {

    s1 += " Happy Birthday ";
    s1 += ds1.Tables["imagepath"].Rows[0][0].ToString();
    }
    s1 += "      ";
    if (ds1.Tables["imagepath"].Rows.Count > 1)
    {
    s1 += " HappyBirthday ";
    s1 += "      ";


    s1 += ds1.Tables["imagepath"].Rows[1][0].ToString();
    }
    s1 += "      ";
    if (ds1.Tables["imagepath"].Rows.Count > 2)
    {
    s1 += " HappyBirthday ";
    s1 += "      ";

    s1 += ds1.Tables["imagepath"].Rows[2][0].ToString();
    }
    s1 += "      ";
    if (ds1.Tables["imagepath"].Rows.Count > 3)
    {
    s1 += " HappyBirthday ";
    s1 += "      ";

    s1 += ds1.Tables["imagepath"].Rows[3][0].ToString();
    }

    lt1.Text = s1.ToString();


    }

    }
    // string sqlconstr = "Data Source=HOME;Initial Catalog=Registration;Integrated Security=True";


    protected void Timer11_Tick(object sender, EventArgs e)
    {
    CurrentRecord++;
    if (CurrentRecord == TotalRecords)
    {
    CurrentRecord = 0;

    }
    Image1.ImageUrl = "~/Upload/" + dt.Rows[CurrentRecord]["newimagepath"].ToString();
    // Image1.ImageUrl = "~/Upload/" + dt.Rows[CurrentRecord]["newimagepath"].ToString();
    //Image1.ImageUrl = @"C:\Users\admin\Documents\Visual Studio 2012\WebSites\uploadsite\Upload\";
    }

    }
  • #762214
    Hello Velidi Viram,

    If your code is working properly than create one function and write your image binding code to that function and call it through java script function.

    Refer the below sample code :

    <script type="text/javascript">
    function CallButtonClick2()
    { document.getElementById('Button2').click();
    }
    </script>

    <a onclick="CallButtonClick2()" href="javascript:void('0');">Call Server Function</a>
    <asp:Button ID="Button2" runat="server" Text="Call Button Click" Style="display:none" OnClick="Button2_Click" />

    protected void Button2_Click(object sender, EventArgs e)
    {
    Response.Write("Button method called");
    }

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762217
    Hi
    Velin

    Listen 2 things

    1. First when you change the system date after in your refreshing then c# code go to sql server then fetch the data and populated in your did not refresh means you canot fetch the data so this is the Rule.

    2.Check your records have which is you changed date corresponding data in your database.

    Normally when you change date after page repost then you get the data otherwise you canot do

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments