Difference between two dates in textboxes Using Mysql StoredProcedure with between query

Difference between two dates in textboxes Using Mysql StoredProcedure with between query

Calculate two different textboxs dates using Mysql Stored procedure database . select in between database details using above query.i used order by for sort details.

DEMO



MySQL Stored Procedure


CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_select_DateDifference`(In vfromdate varchar(15),In vtodate varchar(15))
BEGIN

select * from `userinformation` where fromdate between  CAST(vfromdate as DATE) AND CAST(vtodate AS DATE) order by fromdate;

END


HTML CODING


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
    <table><tr><td>From Date</td><td>
        <asp:TextBox ID="txtFrom" runat="server" TextMode="Date"></asp:TextBox>
        </td></tr>
        <tr><td>To Date</td><td>
            <asp:TextBox ID="txtTo" runat="server" TextMode="Date"></asp:TextBox>
            </td></tr>
        <tr><td></td><td>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Search" />
            </td></tr>
        <tr><td>&nbsp;</td><td>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
                <Columns>
             <asp:BoundField DataField="UserId" HeaderText="User Id" />
            <asp:BoundField DataField="UserName" HeaderText="User Name" />
            <asp:BoundField DataField="Location" HeaderText="Location" />
            <asp:BoundField DataField="fromdate" HeaderText="FromDates" />
                </Columns>
                <HeaderStyle ForeColor="#CC3300" />
            </asp:GridView>
            </td></tr>
    </table>
    </div>
    </form>
</body>
</html>


C# CODING


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;

public partial class Mysql_StoredProcedure : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbc"].ToString());
        con.Open();
        MySqlCommand cmd =new MySqlCommand("sp_select_DateDifference",con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@vfromdate",txtFrom.Text.ToString());
        cmd.Parameters.AddWithValue("@vtodate", txtTo.Text.ToString());
        MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
        DataSet ds=new DataSet();
        adp.Fill(ds);
        if(ds.Tables[0].Rows.Count>0)
        {
            GridView1.DataSource=ds;
            GridView1.DataBind();
        }
        con.Close();

    }

}



First - Add New Form and add textboxes and gridview textbox - property - TextMode=Date





Next  - Add Code Source file - database connect - add mysql namespaces - Parameter set stored procedure





Next - Create Stored Procedure two dates parameter and select query date in varchar format i convert to DATE Format  CAST(vfromdate AS DATE) 






Database Details 



Table Structure





0 comments:

Post a Comment