473,467 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help needed to create BLL class for storeprocedure which updates multiple tables

10 New Member
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.

Unable to cast object of type 'System.Data.DataSet' to type 'Project1'.

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Data.DataSet' to type 'Project1'.

Line 24: productsTableAdapter.Update(MyDataSet)
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 QueriesTableAdapter in xsd file (DAL). Right now I created BLL class for the same. Below is the VB class.

Expand|Select|Wrap|Line Numbers
  1. Imports Microsoft.VisualBasic
  2. Imports ProjectTableAdapters
  3. Imports System.Data
  4. <System.ComponentModel.DataObject()> _
  5. Public Class QueriesBLL
  6.     Private _queriesAdapter As QueriesTableAdapter = Nothing
  7.     Protected ReadOnly Property Adapter() As QueriesTableAdapter
  8.         Get
  9.             If _queriesAdapter Is Nothing Then
  10.                 _queriesAdapter = New QueriesTableAdapter()
  11.             End If
  12.             Return _queriesAdapter
  13.         End Get
  14.     End Property
  15.  
  16. <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, True)> _
  17.     Public Function AddProductFullDetails(ByVal categoryID As Nullable(Of Integer), ByVal description As String, ByVal isRound As Boolean, _
  18.     ByVal productStory As String, ByVal materialID As Integer, ByVal isActive As Boolean, ByVal featureName As String, ByVal modifiedDate As DateTime) As Boolean
  19.         Dim MyDataSet As New DataSet
  20.         Dim productsTableAdapter As New ProductsTableAdapter()
  21.         Dim featuresTableAdapter As New FeaturesTableAdapter()
  22.         Dim productsfeaturesTableAdapter As New ProductsFeaturesTableAdapter()
  23.         productsTableAdapter.Update(MyDataSet)
  24.         featuresTableAdapter.Update(MyDataSet)
  25.         productsfeaturesTableAdapter.Update(MyDataSet)
  26.     End Function
  27.  
  28. End 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:

Expand|Select|Wrap|Line Numbers
  1. SET ANSI_NULLS ON
  2. GO
  3. SET QUOTED_IDENTIFIER ON
  4. GO
  5. ALTER PROCEDURE [Product].[AddProductFullDetails]
  6. (
  7.     @CategoryID int,
  8.     @Description varchar(50),
  9.     @IsRound bit,
  10.     @ProductStory nvarchar(1000),
  11.     @MaterialID int,
  12.     @IsActive bit,
  13.     @FeatureName varchar(500),
  14.     @ModifiedDate smalldatetime,
  15.     @ProductID int OUTPUT,
  16.     @FeatureID int OUTPUT
  17. )
  18. AS
  19. BEGIN TRANSACTION
  20. SET @ModifiedDate = getdate()
  21. SET NOCOUNT OFF;
  22. INSERT INTO [Product].[Products] ([CategoryID], [Description], [IsRound], [Story], [MaterialID], [IsActive], [ModifiedDate]) VALUES (@CategoryID, @Description, @IsRound, @ProductStory, @MaterialID, @IsActive, @ModifiedDate)
  23. SET @ProductID = SCOPE_IDENTITY();
  24. IF @@ERROR <> 0
  25.  BEGIN
  26.     ROLLBACK
  27.     RAISERROR ('Error in adding products.', 16, 1)
  28.     RETURN
  29.  END
  30. INSERT INTO [Product].[Features] ([Name], [ModifiedDate]) VALUES (@FeatureName, @ModifiedDate)
  31. SET @FeatureID = SCOPE_IDENTITY();
  32. IF @@ERROR <> 0
  33.  BEGIN
  34.     ROLLBACK
  35.     RAISERROR ('Error in adding features.', 16, 1)
  36.     RETURN
  37.  END
  38. INSERT INTO [Product].[ProductsFeatures] SELECT @ProductID, @FeatureID, @ModifiedDate;
  39. IF @@ERROR <> 0
  40.  BEGIN
  41.     ROLLBACK
  42.     RAISERROR ('Error in adding features & Products IDs.', 16, 1)
  43.     RETURN
  44.  END
  45. COMMIT
May 12 '09 #1
6 4170
Frinavale
9,735 Recognized Expert Moderator Expert
What is a BLL class? (What does BLL stand for?)

I would take a look at the Update() method that is a member of the ProductsTableAdapter class and see what it expects as a parameter.
May 12 '09 #2
nzkks
10 New Member
Sorry for the misunderstanding. BLL - Business Logic Layer. Any way, I am sure you know the 3-tier architechure (Data Access Layer(DAL) | BLL | Presentation Layer (ASP.Net pages + all supporting documents)). May be this is a Microsoft term?!

But I am very much sure you can solve this problem. OK the scenario below.

After I created the SQL tables + all data modification store procedures in SQL server 2005, In Visual studio 2005, I created the data tables and data adapters for each sql tables. Then I wrote all the VB classes for CRUD operations. In that way, I created the above VB class (I know something is missing but don't know what!) for the store procedure that supports inserting data into multiple tables.

Please help.
May 12 '09 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Sorry I'm a little slow today.
I usually don't have any database stuff in my business logic, that's what my data access layer does...so I was a little confused when you were talking about accessing database content in your business logic layer.

Anyways, could you please post the code for the Update() method that is a member of the ProductsTableAdapter class.
May 12 '09 #4
nzkks
10 New Member
Now I changed the VB code to:

Expand|Select|Wrap|Line Numbers
  1.     <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, True)> _
  2.     Public Function AddProductFullDetails(ByVal categoryID As Nullable(Of Integer), ByVal description As String, ByVal isRound As Boolean, _
  3.     ByVal productStory As String, ByVal materialID As Integer, ByVal isActive As Boolean, ByVal featureName As String, ByVal modifiedDate As DateTime) As Boolean
  4.  
  5.         Dim productsTableAdapter As New ProductsTableAdapter()
  6.         Dim featuresTableAdapter As New FeaturesTableAdapter()
  7.         Dim productsfeaturesTableAdapter As New ProductsFeaturesTableAdapter()
  8.  
  9.         Dim products As New Project1.ProductsDataTable()
  10.         Dim product As Project1.ProductsRow = products.NewProductsRow()
  11.  
  12.         Dim features As New Project1.FeaturesDataTable()
  13.         Dim feature As Project1.FeaturesRow = features.NewFeaturesRow()
  14.  
  15.         Dim productsfeatures As New Project1.ProductsFeaturesDataTable()
  16.         Dim productfeature As Project1.ProductsFeaturesRow = productsfeatures.NewProductsFeaturesRow()
  17.  
  18.  
  19.         products.AddProductsRow(product)
  20.         productsTableAdapter.Update(products)
  21.  
  22.         features.AddFeaturesRow(feature)
  23.         featuresTableAdapter.Update(features)
  24.  
  25.         productsfeatures.AddProductsFeaturesRow(productfeature)
  26.         productsfeaturesTableAdapter.Update(productsfeatures)
  27.     End Function
  28.  
Now it seems to work. But because of some other error, it is not inserting. But I will update you the status. Please be with me. Thanks
May 12 '09 #5
nzkks
10 New Member
I couldn't find what is wrong and where by seeing the exception details. Somebody please help.

Error below:

Expand|Select|Wrap|Line Numbers
  1. Column 'ProductID' does not allow nulls
  2.  
  3. Exception Details: System.Data.NoNullAllowedException: Column 'ProductID' does not allow nulls.
  4.  
  5. Line 9190:        <Global.System.Diagnostics.DebuggerNonUserCodeAttribute()>  _
  6. Line 9191:        Public Overloads Sub AddProductsFeaturesRow(ByVal row As ProductsFeaturesRow)
  7. Line 9192:            Me.Rows.Add(row)
  8. Line 9193:        End Sub
  9.  
  10. Stack Trace:
  11.  
  12. [NoNullAllowedException: Column 'ProductID' does not allow nulls.]
  13.    System.Data.DataColumn.CheckNullable(DataRow row) +2030879
  14.    System.Data.DataTable.RaiseRowChanging(DataRowChangeEventArgs args, DataRow eRow, DataRowAction eAction, Boolean fireEvent) +133
  15.    System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Int32 position, Boolean fireEvent, Exception& deferredException) +265
  16.    System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID, Int32 pos, Boolean fireEvent) +254
  17.    System.Data.DataRowCollection.Add(DataRow row) +20
  18.    ProductsFeaturesDataTable.AddProductsFeaturesRow(ProductsFeaturesRow row) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\Project1\7ad4c5d5\4bdb9089\App_Code.4ca2yx3k.7.vb:9192
  19.    QueriesBLL.AddProductFullDetails(Nullable`1 categoryID, String description, Boolean isRound, String productStory, Nullable`1 materialID, Boolean isActive, String featureName, DateTime modifiedDate) in C:\Project Websites\Project1\App_Code\BLL\QueriesBLL.vb:41
  20.  
  21. [TargetInvocationException: Exception has been thrown by the target of an invocation.]
  22.    System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
  23.    System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
  24.    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +371
  25.    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
  26.    System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +480
  27.    System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method) +38
  28.    System.Web.UI.WebControls.ObjectDataSourceView.ExecuteInsert(IDictionary values) +867
  29.    System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +72
  30.    System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation) +388
  31.    System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +602
  32.    System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) +95
  33.    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
  34.    System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +109
  35.    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
  36.    System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115
  37.    System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +132
  38.    System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
  39.    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
  40.    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177
  41.    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
  42.  
May 13 '09 #6
shiznit770
10 New Member
Looks like you're trying to insert into the products table without a ProductID and you have the column set to not allow Nulls. You need to set the column to auto increment or specify a value for it if you're going to not allow Nulls.
May 13 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Cndistin | last post by:
First I am sorry for the title but I an newbie enough to now know how to better word it. The problem part of my code is class Application: class Moon: def __init__(self, name): self.name =...
2
by: Beyonder | last post by:
I have five tables in my database, there are actually NO common fields between them, not even a KEY or ID or anything like that, except for the "body" of a blob field. and that text is not...
1
by: none | last post by:
how can I do this type of join: table1: id, value1, value2 table2: id, value1, value2 table3: id, value1, value2 the "id" is a product code the values are new & used pricing
2
by: Anan18 | last post by:
Use Integer variables to represent the private data of the class – the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it is...
10
by: VirtualLilac | last post by:
Hi, Am trying to build a database for non-profit organisation, its a volunteer job and nobody around to guide me. From my learning I could able to build few reports and forms but am feeling stuck...
1
by: keveen | last post by:
Can someone tell me how I can import tables from another non-Joomla mysql file into Joomla? Basically it is just from one mySQL database into another. I use phpMyAdmin to import and export the entire...
0
by: SamKhazary | last post by:
I have created a database that has a main table with a description of different products. I have 5 other data bases that are linked sheets that have returns for the 5 different prduct groups. I'd...
3
by: dponce | last post by:
Hello, I need some help, this is what I am trying to accomplish. I have 14 different tables, all the tables have the same colums but different information is recorded in each one. What I am trying...
4
by: knix | last post by:
I have this access project consisting of multiple tables that are linked together in a relationship. I would like to migrate the consolidated information through appending in a datasheet form or...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.