Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>View Docket Values </title>
</head>
<body>
<form id="form1" runat="server">
    <div>
        <asp:Label ID="Date1" runat="server" Text="From Date"></asp:Label>
        <asp:TextBox ID="DateFrom" runat="server"></asp:TextBox>
        <asp:Label ID="Date2" runat="server" Text="To Date"></asp:Label>
        <asp:TextBox ID="ToDate" runat="server"></asp:TextBox>
        <asp:Button ID="Show" runat="server" Text="ShowData" OnClick="Show_Click" />
    </div>
<div>
<asp:GridView runat="server" ID="gvrecords"  AutoGenerateColumns="false" ShowFooter="true" HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White" DataKeyNames="DocketNo" Width="80px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href ='<%#"UpdateDocket.aspx?DocketNo="+DataBinder.Eval(Container.DataItem,"DocketNo") %>'> <%#Eval("DocketNo") %>  </a>
</ItemTemplate>
</asp:TemplateField>
    <asp:BoundField DataField="ConsignorName" HeaderText="Consigner" />
    <asp:BoundField DataField="ConsigneeName" HeaderText="Consignee" />
    <asp:BoundField DataField="Date" HeaderText="Booking Date" />
    <asp:BoundField DataField="FromSTN" HeaderText="Booking Station" />
    <asp:BoundField DataField="ToStn" HeaderText="Delivery Station" />
    <asp:BoundField DataField="PKG" HeaderText="No. of Packets" />
    <asp:BoundField DataField="ActualWt" HeaderText="Actual Weight" />
    <asp:BoundField DataField="ChargeWt" HeaderText="Charge Weight" />
    <asp:BoundField DataField="InvoiceValue" HeaderText="Invoice Value" />
    <asp:BoundField DataField="Basis" HeaderText="Basis" />
    <asp:BoundField DataField="FreightCharge" HeaderText="Freight Charge" />
    <asp:BoundField DataField="FuelSurcharge" HeaderText="Fuel Surcharge" />
    <asp:BoundField DataField="FOV" HeaderText="FOV" />
    <asp:BoundField DataField="COD" HeaderText="COD" />
    <asp:BoundField DataField="FOD" HeaderText="FOD" />
    <asp:BoundField DataField="PickupCharge" HeaderText="Pickup Charge" />
    <asp:BoundField DataField="DoorDelivery" HeaderText="Door Delivery" />
    <asp:BoundField DataField="Handling" HeaderText="Handling" />
    <asp:BoundField DataField="Misc" HeaderText="Misc" />
    <asp:BoundField DataField="DktCharge" HeaderText="Docket Charge" />
    <asp:BoundField DataField="SubTotal" HeaderText="Sub Total" />
    <asp:BoundField DataField="ServiceTax" HeaderText="Service Tax" />
    <asp:BoundField DataField="GrandTotal" HeaderText="Grand Total" />
    <asp:BoundField DataField="Service" HeaderText="Service" />
</Columns>
</asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:amitpandeyConnectionString %>" SelectCommand="SELECT * FROM [Docket]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>

and the C# Code is
C#
public partial class Docket : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridview();
        }
    }
    protected void BindGridview()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["amitpandeyConnectionString"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from Docket", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        cmd.ExecuteNonQuery();
        con.Close();
        DataSet ds = new DataSet();
        da.Fill(ds);
        gvrecords.DataSource = ds;
        gvrecords.DataBind();
        DataSet db = new DataSet();
        da.Fill(db);
        gvrecords.Columns[7].FooterText = (from row in dt.AsEnumerable() select row.Field("ActualWt")).Skip(gvrecords.PageIndex * gvrecords.PageSize).Take(gvrecords.PageSize).Sum().ToString("C", ActualWt).Remove(0, 2).Trim();
        gvrecords.DataSource = ds;
        gvrecords.DataBind();

    }

    protected void Show_Click(object sender, EventArgs e)
    {

    }
}


my problem is I want to select two dates with the help of textbox and I want to show the data inside those two dates with the help of a button
Posted
Updated 6-Mar-15 20:45pm
v2

To prevent from sql injection, Always use Parameterised Query.
Try like this,
C#
SqlCommand cmd = new SqlCommand("select * from Docket where yourDate between @FromDate and @ToDate", con);
//Declare it Globally
DateTime FromDate;
DateTime Todate;
System.Globalization.CultureInfo culmoney = new System.Globalization.CultureInfo("hi-IN",true);

FromDate = DateTime.Parse(txtFromDate.Text.Trim(), cul, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
                Todate = DateTime.Parse(txtTodate.Text.Trim(), cul, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
                cmd.Parameters.AddWithValue("@FromDate", FromDate.ToShortDateString());
                cmd.Parameters.AddWithValue("@ToDate", Todate.ToShortDateString());
 
Share this answer
 
v3
Try This.............
SQL
select * from Docket where [Date] between Convert(Datetime,'"+ TextBox1.Text +"',102) and Convert(Datetime,'"+ TextBox2.Text +"',102) 



Regards,
AARIF SHAIKH
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900