I currently have the following sql which works 100%. This sql is a stored proc which gets called from C# code.When i run this the data is 100% and the .NET grids get populated correctly, etc
CREATE DEFINER=`root`@`localhost` PROCEDURE `view_sr_projects_header`(
IN userName varchar(20),
OUT projectCode int,
OUT projectName text,
OUT projectCreationDate DATETIME,
OUT projectEndDate DATETIME,
OUT projectStatus varchar(8),
OUT daysLeft int)
BEGIN
SELECT
project_code as projectCode,
project_name as projectName,
project_creation_date as projectCreationDate,
project_end_date as projectEndDate,
project_status as projectStatus,
datediff(date(project_end_date),date(project_creation_date)) as daysLeft
from projects
where sr_user_name = userName
order by project_status, project_creation_date desc;
END
However, when i change the above to this:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `view_sr_projects_header`(
IN userName varchar(20),
OUT projectCode int,
OUT projectName text,
OUT projectCreationDate DATETIME,
OUT projectEndDate DATETIME,
OUT projectStatus varchar(8),
OUT noOfBids int,
OUT daysLeft int)
BEGIN
SELECT
a.project_code as projectCode,
a.project_name as projectName,
a.project_creation_date as projectCreationDate,
a.project_end_date as projectEndDate,
a.project_status as projectStatus,
count(b.project_code) as noOfBids,
datediff(date(project_end_date),date(project_creation_date)) as daysLeft
from projects a
left join project_bids b
on b.project_code = a.project_code
where sr_user_name = userName
group by b.project_code
order by project_status, project_creation_date desc;
END
It does not work. I run this from MYSQL WorkBench, and it works fine. The output is correct. The error i am getting when debugging is "Specified cast is not valid" "Invalid cast Exception was unhandled by user code"
The error occurs for the "daysLeft" column. The newly added column is the noOfBids. So i dont quite understand why its failing on an existing column. I have removed the noOfBids column from the stored proc and from the C# code, and it works fine. As soon as i add this in, it fails on the daysLeft, which is an existing field. Please can you assist.
thanks
naren
CREATE DEFINER=`root`@`localhost` PROCEDURE `view_sr_projects_header`(
IN userName varchar(20),
OUT projectCode int,
OUT projectName text,
OUT projectCreationDate DATETIME,
OUT projectEndDate DATETIME,
OUT projectStatus varchar(8),
OUT daysLeft int)
BEGIN
SELECT
project_code as projectCode,
project_name as projectName,
project_creation_date as projectCreationDate,
project_end_date as projectEndDate,
project_status as projectStatus,
datediff(date(project_end_date),date(project_creation_date)) as daysLeft
from projects
where sr_user_name = userName
order by project_status, project_creation_date desc;
END
However, when i change the above to this:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `view_sr_projects_header`(
IN userName varchar(20),
OUT projectCode int,
OUT projectName text,
OUT projectCreationDate DATETIME,
OUT projectEndDate DATETIME,
OUT projectStatus varchar(8),
OUT noOfBids int,
OUT daysLeft int)
BEGIN
SELECT
a.project_code as projectCode,
a.project_name as projectName,
a.project_creation_date as projectCreationDate,
a.project_end_date as projectEndDate,
a.project_status as projectStatus,
count(b.project_code) as noOfBids,
datediff(date(project_end_date),date(project_creation_date)) as daysLeft
from projects a
left join project_bids b
on b.project_code = a.project_code
where sr_user_name = userName
group by b.project_code
order by project_status, project_creation_date desc;
END
It does not work. I run this from MYSQL WorkBench, and it works fine. The output is correct. The error i am getting when debugging is "Specified cast is not valid" "Invalid cast Exception was unhandled by user code"
The error occurs for the "daysLeft" column. The newly added column is the noOfBids. So i dont quite understand why its failing on an existing column. I have removed the noOfBids column from the stored proc and from the C# code, and it works fine. As soon as i add this in, it fails on the daysLeft, which is an existing field. Please can you assist.
thanks
naren