We help IT Professionals succeed at work.
Get Started

LinqDataSource or SqlDataSource Pass Parameter

Last Modified: 2013-11-10
I am trying to insert a non-nullable value into the Inserting event of a SqlDataSource or LinqDataSource.

My first preference is the LinqDataSource. I get an error:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Failed to set one or more properties on type LessonType.dstroke_LessonType.   is not a valid value for Int32.

After I couldn't find a solution, I decided to see if I could make a SqlDataSource do the job and I get:
Value cannot be null. Parameter name: value

Protected Sub LessonTypeLinqDataSource_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceInsertEventArgs) Handles LessonTypeLinqDataSource.Inserting
            Dim lessonType As New dstroke_LessonType
            lessonType.ModuleID = ModuleId
        End Sub
Protected Sub LessonTypeSqlDataSource_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles LessonTypeSqlDataSource.Inserting
            e.Command.CreateParameter.Value = ModuleId
            Dim sqlea As SqlDataSource = LessonTypeSqlDataSource
            sqlea.InsertParameters("ModuleID") = e.Command.CreateParameter.Value
        End Sub

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE