D
David C
I am getting the following error after inserting a record in a SqlDataSource
and cannot figure out why.
Object cannot be cast from DBNull to other types.
I have below at the end of my stored procedure
RETURN SCOPE_IDENTITY();
In my SqlDataSource I have the Insert Command below
InsertCommand="EXEC mc_insBudgets @PersonID, @EnteredBy,
@ApprovedDate, @CreatedDate, @FirstName, @LastName, @MiddleName,
@MedicaidID, @Birthdate, @PartTypeID, @AnnualAllocation,
@BudgetEffectiveDate, @BudgetEndingDate, @Address1, @Address2, @City,
@State, @ZipCode, @Gender, @SSN, @Phone, @Email"
InsertCommandType="StoredProcedure">
In my InsertParameters I have below.
<InsertParameters>
<asparameter Name="PersonID" Type="Int32" DefaultValue="0" />
<asparameter Name="EnteredBy" Type="String" />
<asparameter Name="ApprovedDate" DbType="Date" />
<asparameter Name="CreatedDate" DbType="Date" />
<asparameter Name="FirstName" Type="String" />
<asparameter Name="LastName" Type="String" />
<asparameter Name="MiddleName" Type="String" />
<asparameter Name="Address1" Type="String" />
<asparameter Name="Address2" Type="String" />
<asparameter Name="City" Type="String" />
<asparameter Name="State" Type="String" />
<asparameter Name="ZipCode" Type="String" />
<asparameter Name="Gender" Type="String" />
<asparameter Name="SSN" Type="Int32" />
<asparameter Name="Phone" Type="String" />
<asparameter Name="Email" Type="String" />
<asparameter Name="MedicaidID" Type="String" />
<asparameter Name="Birthdate" DbType="Date" />
<asparameter Name="PartTypeID" Type="Int32" />
<asparameter Name="AnnualAllocation" Type="Decimal" />
<asparameter Name="BudgetEffectiveDate" DbType="Date" />
<asparameter Name="BudgetEndingDate" DbType="Date" />
<asparameter Name="NewBudgetID" Type="Int32"
Direction="ReturnValue" />
</InsertParameters>
In my SqlDataSource ItemInserted event I have the following.
Protected Sub SqlBudgets_Inserted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles
SqlBudgets.Inserted
Dim newBudgetID As Integer =
Convert.ToInt32(e.Command.Parameters("@NewBudgetID").Value)
txtBudgetID.Text = newBudgetID.ToString
.....etc
End Sub
The error is occurring in the DIM line because apparently the parameter
value is null and I don't know why.
Any help is appreciated.
David
and cannot figure out why.
Object cannot be cast from DBNull to other types.
I have below at the end of my stored procedure
RETURN SCOPE_IDENTITY();
In my SqlDataSource I have the Insert Command below
InsertCommand="EXEC mc_insBudgets @PersonID, @EnteredBy,
@ApprovedDate, @CreatedDate, @FirstName, @LastName, @MiddleName,
@MedicaidID, @Birthdate, @PartTypeID, @AnnualAllocation,
@BudgetEffectiveDate, @BudgetEndingDate, @Address1, @Address2, @City,
@State, @ZipCode, @Gender, @SSN, @Phone, @Email"
InsertCommandType="StoredProcedure">
In my InsertParameters I have below.
<InsertParameters>
<asparameter Name="PersonID" Type="Int32" DefaultValue="0" />
<asparameter Name="EnteredBy" Type="String" />
<asparameter Name="ApprovedDate" DbType="Date" />
<asparameter Name="CreatedDate" DbType="Date" />
<asparameter Name="FirstName" Type="String" />
<asparameter Name="LastName" Type="String" />
<asparameter Name="MiddleName" Type="String" />
<asparameter Name="Address1" Type="String" />
<asparameter Name="Address2" Type="String" />
<asparameter Name="City" Type="String" />
<asparameter Name="State" Type="String" />
<asparameter Name="ZipCode" Type="String" />
<asparameter Name="Gender" Type="String" />
<asparameter Name="SSN" Type="Int32" />
<asparameter Name="Phone" Type="String" />
<asparameter Name="Email" Type="String" />
<asparameter Name="MedicaidID" Type="String" />
<asparameter Name="Birthdate" DbType="Date" />
<asparameter Name="PartTypeID" Type="Int32" />
<asparameter Name="AnnualAllocation" Type="Decimal" />
<asparameter Name="BudgetEffectiveDate" DbType="Date" />
<asparameter Name="BudgetEndingDate" DbType="Date" />
<asparameter Name="NewBudgetID" Type="Int32"
Direction="ReturnValue" />
</InsertParameters>
In my SqlDataSource ItemInserted event I have the following.
Protected Sub SqlBudgets_Inserted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles
SqlBudgets.Inserted
Dim newBudgetID As Integer =
Convert.ToInt32(e.Command.Parameters("@NewBudgetID").Value)
txtBudgetID.Text = newBudgetID.ToString
.....etc
End Sub
The error is occurring in the DIM line because apparently the parameter
value is null and I don't know why.
Any help is appreciated.
David