Hi I am using these: ASP.Net 2.0 with VB.Net, Visual Studio 2005, SQL Server 2005
I suspect, there is something missing in BLL class.
I created the ASP.Net form also and checked whether it is working or not. When I submit after entering the data, an error comes.
Please help me to solve this problem. Thanks
The details below:
I have created a store procedure to insert data to multiple tables. I have created QueriesTableAda pter in xsd file (DAL). Right now I created BLL class for the same. Below is the VB class.
I also created proper data tables and data adapters for all the tables with CRUD store procedures. Individually If I create a ASP.Net form each to perform CRUD operation per table, It works. But I wanted to combine inserting data to all related tables. In the above BLL VB class, three tables are involved.
Below is the SQL query:
I suspect, there is something missing in BLL class.
I created the ASP.Net form also and checked whether it is working or not. When I submit after entering the data, an error comes.
Unable to cast object of type 'System.Data.Da taSet' to type 'Project1'.
Exception Details: System.InvalidC astException: Unable to cast object of type 'System.Data.Da taSet' to type 'Project1'.
Line 24: productsTableAd apter.Update(My DataSet)
Exception Details: System.InvalidC astException: Unable to cast object of type 'System.Data.Da taSet' to type 'Project1'.
Line 24: productsTableAd apter.Update(My DataSet)
The details below:
I have created a store procedure to insert data to multiple tables. I have created QueriesTableAda pter in xsd file (DAL). Right now I created BLL class for the same. Below is the VB class.
Code:
Imports Microsoft.VisualBasic
Imports ProjectTableAdapters
Imports System.Data
<System.ComponentModel.DataObject()> _
Public Class QueriesBLL
Private _queriesAdapter As QueriesTableAdapter = Nothing
Protected ReadOnly Property Adapter() As QueriesTableAdapter
Get
If _queriesAdapter Is Nothing Then
_queriesAdapter = New QueriesTableAdapter()
End If
Return _queriesAdapter
End Get
End Property
<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, True)> _
Public Function AddProductFullDetails(ByVal categoryID As Nullable(Of Integer), ByVal description As String, ByVal isRound As Boolean, _
ByVal productStory As String, ByVal materialID As Integer, ByVal isActive As Boolean, ByVal featureName As String, ByVal modifiedDate As DateTime) As Boolean
Dim MyDataSet As New DataSet
Dim productsTableAdapter As New ProductsTableAdapter()
Dim featuresTableAdapter As New FeaturesTableAdapter()
Dim productsfeaturesTableAdapter As New ProductsFeaturesTableAdapter()
productsTableAdapter.Update(MyDataSet)
featuresTableAdapter.Update(MyDataSet)
productsfeaturesTableAdapter.Update(MyDataSet)
End Function
End Class
Below is the SQL query:
Code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [Product].[AddProductFullDetails]
(
@CategoryID int,
@Description varchar(50),
@IsRound bit,
@ProductStory nvarchar(1000),
@MaterialID int,
@IsActive bit,
@FeatureName varchar(500),
@ModifiedDate smalldatetime,
@ProductID int OUTPUT,
@FeatureID int OUTPUT
)
AS
BEGIN TRANSACTION
SET @ModifiedDate = getdate()
SET NOCOUNT OFF;
INSERT INTO [Product].[Products] ([CategoryID], [Description], [IsRound], [Story], [MaterialID], [IsActive], [ModifiedDate]) VALUES (@CategoryID, @Description, @IsRound, @ProductStory, @MaterialID, @IsActive, @ModifiedDate)
SET @ProductID = SCOPE_IDENTITY();
IF @@ERROR <> 0
BEGIN
ROLLBACK
RAISERROR ('Error in adding products.', 16, 1)
RETURN
END
INSERT INTO [Product].[Features] ([Name], [ModifiedDate]) VALUES (@FeatureName, @ModifiedDate)
SET @FeatureID = SCOPE_IDENTITY();
IF @@ERROR <> 0
BEGIN
ROLLBACK
RAISERROR ('Error in adding features.', 16, 1)
RETURN
END
INSERT INTO [Product].[ProductsFeatures] SELECT @ProductID, @FeatureID, @ModifiedDate;
IF @@ERROR <> 0
BEGIN
ROLLBACK
RAISERROR ('Error in adding features & Products IDs.', 16, 1)
RETURN
END
COMMIT
Comment