Avatar of wdarnellg
wdarnellgFlag for United States of America asked on

LinqDataSource or SqlDataSource Pass Parameter

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

Microsoft DevelopmentASP.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

I get an error now:
An SqlParameter with ParameterName 'ModuleId' is not contained by this SqlParameterCollection.

the ascx source code has the declaration I think.
        <asp:Parameter Name="ModuleID" Type="Int32" />
        <asp:Parameter Name="TypeName" Type="String" />
        <asp:Parameter Name="NumberOfLessons" Type="Double" />
        <asp:Parameter Name="Location" Type="String" />
        <asp:Parameter Name="Description" Type="String" />
        <asp:Parameter Name="Cost" Type="Double" />

Open in new window


I figured out to make the parameter "@ModuleID", but you were right, I didn't need all that code.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck