Hi
I am working with DAL2 as taugh by Charles Nurse in his blog
http://www.charlesnurse.com/Blog/tabid/226/EntryId/69/DAL-2-DataContext-Deep-Dive.aspx
and have come across an unexpected error using ExecuteScalar<T>.
My stored procedure fires and inserts to the database but somewhere after that the code errors with a 'Invalid attempt to read when no data is present.'. The code in question is
public int AddLocation(string LocationType, string Name, string Description, string Address, string AreaCode, string Telephone, int Capacity, float Long, float Lat)
{
int id;
using (IDataContext db = DataContext.Instance())
{
id = db.ExecuteScalar<
int
>(CommandType.StoredProcedure,
"CP_AddLocation", LocationType, Name, Description, Address, AreaCode, Telephone, Capacity, Long, Lat);
}
return id;
}
My Sproc is
CREATE PROCEDURE [dbo].[CP_AddLocation]
@locationType nvarchar(100),
@name nvarchar(100),
@description nvarchar(200),
@address nvarchar(250),
@areaCode nvarchar(50),
@telephone nvarchar(50),
@capacity int,
@long float,
@lat float
AS
DECLARE @geoCode geography
SET @geoCode = geography:: STGeomFromText('POINT (' + CAST(@long AS varchar) + ' ' + CAST(@lat AS varchar) + ')',4326);
BEGIN
INSERT INTO CP_Locations(
LocationType,
Name,
Description,
Address,
AreaCode,
Telephone,
GeoCode,
Capacity,
Long,
Lat)
VALUES(
@locationType,
@name,
@description,
@address,
@areaCode,
@telephone,
@geoCode,
@capacity,
@long,
@lat)
END
declare @locationId int;
select @locationId = SCOPE_IDENTITY()
return @locationId;
I should mention that the stored procedure when run by it self works fine.
What am I doing wrong?
Mark