rachayita jaiswal

rachayita jaiswal

  • NA
  • 217
  • 106.9k

MySql with VB.Net

Jul 16 2013 2:08 AM
Hi,
 
I created stored procedure like - 
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_Analysis_rpt`( _action varchar(20),
 _unitid varchar(10),
 _da1 varchar(20),
 _da2 varchar(20),
 _Driver_query varchar(100),
 _MinDisSpeed varchar(50),
 _MinAvgSpeed varchar(50),
 _AvgSpeed varchar(50))

BEGIN

if _action = 'SelectAnaHalt' then
select * from gprsrecordsview
where TimeStamp between _da1 and _da2
and TrackerId =_UnitId and _Driver_query
And recpos in ('Start','Stop')
order by TimeStamp asc;
end if;

if _action = 'SelectAnaIdle' then
select * from gprsrecordsview
where TimeStamp between _da1 and _da2
and TrackerId =_UnitId and _Driver_query
And ignition_status='ON' and Speed=0 And recpos in ('Start','Stop') 
order by TimeStamp asc;
end if;
END

and in my code behind file i have called this stored procedure like this - 

AnalysisCmd.CommandText = "call SP_Analysis_rpt(?,?,?,?,?,?,?,?)"
        AnalysisCmd.Parameters.AddWithValue("_action", "SelectAnaHalt")
        AnalysisCmd.Parameters.AddWithValue("_da1", da1)
        AnalysisCmd.Parameters.AddWithValue("_da2", da2)
        AnalysisCmd.Parameters.AddWithValue("_UnitId", UnitId)
        AnalysisCmd.Parameters.AddWithValue("_Driver_query", Driver_query)
        AnalysisCmd.Parameters.AddWithValue("_MinDisSpeed", Nothing)
        AnalysisCmd.Parameters.AddWithValue("_MinAvgSpeed", Nothing)
        AnalysisCmd.Parameters.AddWithValue("_AvgSpeed", Nothing)
        AnalysisDR = AnalysisCmd.ExecuteReader()

AnalysisCmd.CommandText = "call SP_Analysis_rpt(?,?,?,?,?,?,?,?)"
        AnalysisCmd.Parameters.AddWithValue("_action", "SelectAnaIdle")
        AnalysisCmd.Parameters.AddWithValue("_da1", da1)
        AnalysisCmd.Parameters.AddWithValue("_da2", da2)
        AnalysisCmd.Parameters.AddWithValue("_UnitId", UnitId)
        AnalysisCmd.Parameters.AddWithValue("_Driver_query", Driver_query)
        AnalysisCmd.Parameters.AddWithValue("_MinDisSpeed", Nothing)
        AnalysisCmd.Parameters.AddWithValue("_MinAvgSpeed", Nothing)
        AnalysisCmd.Parameters.AddWithValue("_AvgSpeed", Nothing)
        AnalysisDR = AnalysisCmd.ExecuteReader()

but this is nopt correct as a code optimization point of view So
is there any other way to call stored procedure in code behind file??