473,796 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ 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.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)
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.

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 4195
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 ProductsTableAd apter class and see what it expects as a parameter.
May 12 '09 #2
nzkks
10 New Member
Sorry for the misunderstandin g. 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 ProductsTableAd apter 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
1153
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 = name def __init__(self): self.moons =
2
2608
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 identical, just a portion of that text is identical. each table has 5 fields, all different except the blob, which is called "message", so normally I use something like: select * from table1 where message like '%apple%';
1
1326
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
3344
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 declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form. For example, the fraction 2/4 should be stored in the object as 1 in the numerator and 2 in the denominator....
10
6864
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 at one point. I have two tables tblWorkers and tblLocations (locations & volunteer positions & start and end time using lookup wiz.) and made relationship using tblJunction. I need to build a form which shows volunteers details and a sub-form...
1
1589
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 file but I don't know how to do queries. I tried exporting the source database and then renaming all the database names to match the ones I want to merge into but all that happened was a new table was created - no merging. I really just want to...
0
1523
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 like to have a query run and pull in all the products with their respective return. Is there a way to have it search for the same field on multiple sheets for example if you are looking for Product Sam, then it will check Return Sheet 1 2 or 3 to pull...
3
1371
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 to do is set up a query to run a report that will give me the total from all 14 tables and just show on one report. Instead of me going into each individual report per table. Thx in advance...
4
3301
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 importing the gathered information . Can anyone please give solutions with my problem? Can I make a datasheet form (consisting fields from multiple tables that are linked together with relationships) in ms access which I could paste append or insert...
0
9531
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10237
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10187
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9055
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6795
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
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 we have to send another system

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.