The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

pprasadravi (2) [Avatar] Offline
#1
Hi,
I am using Linq To SQL. I am very beginer. I have Course and CourseType tables. CourseType table contains definations got coutse. So i am joining these two tables and returning results. In designer i drag and dropped Course and CourseType tables. Below are my vb code and stored procedure. I am getting error "The null value cannot be assigned to a member with type System.Byte which is a non-nullable value type.". Could you please help me to resolve this issue?

Dim xx = CISContext.spCIS_GetCourses(True).ToList()

GridView1.DataSource = xx

GridView1.DataBind()






USE [MyDataBase]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO







CREATE PROCEDURE [dbo].[spCIS_GetCourses]

@Active BIT

AS

BEGIN

SET NOCOUNT ON;



BEGIN TRY

IF @Active IS NULL OR LEN(@Active) = 0

BEGIN

SET @Active = 1

END

SELECT

A.Name as Name,

A.Description as Description,

A.CourseNumber as CourseNumber,

A.BeginDate as BeginDate,

A.EndDate as EndDate,

A.AcademicYear as AcademicYear,

A.DurationInWeeks as DurationInWeeks,

A.Active as DurationInWeeks,

A.UpdatedByID as DurationInWeeks,

A.Objectives as DurationInWeeks,

B.CourseType as CourseType

FROM tblCourse A

INNER JOIN tblLKCourseType B

ON B.CourseTypeID = A.CourseTypeID

where A.Active = @Active

END TRY

BEGIN CATCH


END CATCH

END
jwooley (123) [Avatar] Offline
#2
Re: Linq To SQL
It sounds like the type that is being projected did not correctly infer that one of your columns is nullable and the stored proc is returning a null value for one of the rows. Try running your stored proc manually and look at which columns are returning null values. In this case, the offending column is mapped as a Byte. Without seeing your return type, I can't say for sure which column is the offending one. Since you are using stored procedures, you may want to review chapter 8 which discusses them.

Jim