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


LINQDATASOURCE:
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
 
 
SQLDATASOURCE:
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
wdarnellg
ASKER CERTIFIED SOLUTION
Avatar of Juan_Barrera
Juan_Barrera
Flag of New Zealand image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of wdarnellg
wdarnellg
Flag of United States of America image

ASKER

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.
<InsertParameters>
        <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" />
    </InsertParameters>

Open in new window

Avatar of wdarnellg
wdarnellg
Flag of United States of America image

ASKER

I figured out to make the parameter "@ModuleID", but you were right, I didn't need all that code.
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo