how to get sorted data wihin the region date from and dateto
i have to text boxes textbox1 in which user enter from date and in textbox2 user enetr to date and after button clickevent the gridview will display the record between fromdate and to date..how to write procedure in sql2005?how to write code and where i have to write?datatype is datetime,i am not inserting DateFrom and DateTo in table,,jest select using by datetime picker.i have only one column in table that is 'drpdate'.
Iftikar HussainPosted Jul 16, 2013, 11:45 AM
in your code
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 16, 2013, 11:45 AM
1st add the reference of
using System.Configuration;
public DataTable GET_PRE_SALES_REPORT(string From, string To)
{
string cn= ConfigurationManager.ConnectionStrings["MagnaDBConnection"].ConnectionString;
adap = new SqlDataAdapter("sp_PaymentRegisterGrid", cn);
adap.SelectCommand.CommandType = CommandType.StoredProcedure;
adap.SelectCommand.Parameters.AddWithValue("@from", From);
adap.SelectCommand.Parameters.AddWithValue("@to", To);
dt = new DataTable();
adap.Fill(dt);
return dt;
}
MANEESH ANPosted Jul 16, 2013, 8:52 AM
Sanjeeb LenkaPosted Jul 16, 2013, 8:46 AM
MANEESH ANPosted Jul 16, 2013, 8:44 AM
in this which variable should use for "cn"?
Sanjeeb LenkaPosted Jul 16, 2013, 8:37 AM
cn is your connection string. if you store your connection string in different variable pass it their.
MANEESH ANPosted Jul 16, 2013, 8:32 AM
Ravi ShekharPosted Jul 16, 2013, 7:49 AM
and Use this SP
ALTER PROCEDURE [dbo].[sp_PaymentRegisterGrid]
(
@DTFROM datetime,
@DTTO datetime
)
AS
BEGIN
SELECT
ACC.dRPDate DATE,
ACC.cVType TYPE,
TS.vSeries SERIES,
ACC.iRPNo VOUCHERNO,
ACM.vAcName HEAD,
ACC.vNarration NARRATION,
ACC.deDRAmount DEBIT,
ACC.deCRAmount CREDIT
FROM tbl_Acc_Voucher AS ACC INNER JOIN
tblSerialNumbers AS TS ON ACC.iSeriesId = TS.iSeriesId INNER JOIN
tbl_Acc_AccountMaster AS ACM ON ACM.iAcID = ACC.iAcID
where
convert(DATETIME,dRPDate ,101)>=convert(DATETIME,@DTFROM ,101)
AND
convert(DATETIME,dRPDate ,101) <= convert(DATETIME,@DTTO,101)
END
Iftikar HussainPosted Jul 16, 2013, 7:48 AM
Regards,
Iftikar
MANEESH ANPosted Jul 16, 2013, 7:40 AM
Ravi ShekharPosted Jul 16, 2013, 7:33 AM
SELECT * from table where
convert(DATETIME,CreatedDate,101)>=convert(DATETIME,@From,101)
AND
convert(DATETIME,CreatedDate,101) <= convert(DATETIME,@To,101)
MANEESH ANPosted Jul 16, 2013, 7:13 AM
Ravi ShekharPosted Jul 16, 2013, 6:43 AM
if your sql column is in varchar format .please first convert into proper datetime format...
try below query...
SELECT * from table where
convert(DATETIME,CreatedDate,101)>=convert(DATETIME,@From,101)
AND
convert(DATETIME,CreatedDate,101) <= convert(DATETIME,@To,101)
Mark it as answer if it helped .
Ravi ShekharPosted Jul 16, 2013, 6:21 AM
In which format your column is in sql table.
Iftikar HussainPosted Jul 16, 2013, 5:08 AM
Regards,
Iftikar
MANEESH ANPosted Jul 16, 2013, 5:03 AM
Iftikar HussainPosted Jul 16, 2013, 4:58 AM
Regards,
Iftikar
MANEESH ANPosted Jul 16, 2013, 4:56 AM
MANEESH ANPosted Jul 16, 2013, 4:20 AM
(
@DTFROM datetime,
@DTTO datetime
)
AS
BEGIN
SELECT
ACC.dRPDate DATE,
ACC.cVType TYPE,
TS.vSeries SERIES,
ACC.iRPNo VOUCHERNO,
ACM.vAcName HEAD,
ACC.vNarration NARRATION,
ACC.deDRAmount DEBIT,
ACC.deCRAmount CREDIT
FROM tbl_Acc_Voucher AS ACC INNER JOIN
tblSerialNumbers AS TS ON ACC.iSeriesId = TS.iSeriesId INNER JOIN
tbl_Acc_AccountMaster AS ACM ON ACM.iAcID = ACC.iAcID
where dRPDate >=@DTFROM and dRPDate<=@DTTO
END
DLL
public DataTable fnPayRegDateView(string strWhereCondition)
{
Connection objCon = new Connection();
SqlParameter[] parmsDetails = new SqlParameter[1];
parmsDetails[0] = new SqlParameter();
parmsDetails[0].SqlDbType = SqlDbType.VarChar;
parmsDetails[0].Value = strWhereCondition;
parmsDetails[0].ParameterName = "@WhereCondition";
DataTable dt = new DataTable();
dt = objCon.fnSelectData("sp_PaymentRegisterGridView", parmsDetails);
return dt;
}
IS THIS CORRECT OR NOT?I THINK STRING STRWHERECONDITION IS WRONG?
Iftikar HussainPosted Jul 16, 2013, 3:07 AM
You need to pass from and to date to your stored procedure. And write the query like this
@StartDate and @EndDate are input parametrs of datetime for your SP
SELECT
col1,col2...
FROM
table1
WHERE
CreatedOn>=@StartDate and CreatedOn<=@EndDate
Regards,
Iftikar