Hi
I am a beginner. i have simple table emp with ID,Name and DOB.now on design page i have two text box one as Start date and other is End date.
I have one grid-view so i want to display records between dates entered in text box to grid-view.
please help me.Its urgent
here is my sp
Select * From emp A
Where A.DOB Between @sdtFromDate AND @sdtToDate
Loading
Mukesh Kumar TiwariPosted Nov 16, 2013, 12:25 AM
try
{
Conn = new SqlConnection(ConnString);
if (Conn.State == ConnectionState.Closed)
{
Conn.Open();
}
Cmd = new SqlCommand("Report_call_master_datewise", Conn);
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters.AddWithValue("@f_date", from_Date_datewise.Value);
Cmd.Parameters.AddWithValue("@to_date", to_date_Datewise.Value);
Adp = new SqlDataAdapter(Cmd);
DataSet ds = new DataSet();
Adp.Fill(ds, "call_master");
int a = ds.Tables[0].Rows.Count;
if (a < 1)
{
MessageBox.Show("There are no record between these Date");
Conn.Close();
return;
}
else
{
grid_call_master.DataSource = ds.Tables[0];
Conn.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.tostring());
}
Write a SP in Sql Like below...
ALTER proc [dbo].[Report_call_master_datewise]
(
@f_date datetime,
@to_Date datetime
)
as
begin
select * from Call_Master as cmc
where cmc.c_date between @f_date and @to_date
end
all the best.........
Satyapriya NayakPosted Mar 25, 2013, 12:36 PM
@fromdate varchar(10),
@todate varchar(10)
as
begin
select * from emp where dob between @fromdate and @todate
end
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Search_record_between_from_todate._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Search_record_between_from_todate
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com = new SqlCommand();
SqlDataAdapter sqlda;
DataTable dt = new DataTable();
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
SqlCommand com = new SqlCommand("find", con);
com.Parameters.Add("@fromdate", SqlDbType.VarChar).Value = txtFromDate.Text;
com.Parameters.Add("@todate", SqlDbType.VarChar).Value = txtToDate.Text;
com.CommandType = CommandType.StoredProcedure;
sqlda = new SqlDataAdapter(com);
dt.Clear();
sqlda.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}