473,659 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Partial Class help with designer TableAdapters

SAL
Hello,
I would like to be able to set the WHERE clause of a select statement on the
fly. I have a DataAccess layer designed using the DataSet designer and a
BusinessLogic layer using classes. The business logic layer is decorated
using the
<System.Compone ntModel.DataObj ect()>
attributes and they are used to bind to controls and Object datasets on web
forms.
Is there a resonable way to set the WHERE clause on the fly with a partial
class from a TableAdapter? Some example code maybe?

For instance, I have a table adapter that has a query like the following:
SELECT AssetsId, AssetNumber, AssetReviewed, AssetNotTracked ,
NoLongerAsset, DateAssetDroppe d
FROM dbo.Assets

How can I change that query using partial classes of the Table Adapter...?

SAL
Oct 22 '07 #1
5 1977
Hi SAL,

When you said "and a BusinessLogic layer using classes", do you mean the
class generated by the DataSet designer or your own class? I'm asking this
since the generated TableAdapter partial class also has this attribute:

Global.System.C omponentModel.D ataObjectAttrib ute(true),

If you defined your own custom BusinessLogic class and applied the
DataObjectAttri bute, could you please post some of your code to show how
you're using the TableAdapter?

Based on my understanding so far, you can create a partial class to the
TableAdapter and expose a public method or property to change the
CommandText of the select query to include your where clause. For example:

Namespace DataSet1TableAd apters
Partial Public Class authorsTableAda pter

Public Sub SetWhereClause( ByVal clause As String)
Me.InitCommandC ollection()
Me._commandColl ection(0).Comma ndText += " where " + clause
End Sub

End Class
End Namespace
Dim x As New DataSet1TableAd apters.authorsT ableAdapter
Dim ds As DataSet1.author sDataTable
x.SetWhereClaus e("phone like '4%'")
ds = x.GetData()
Hope this helps.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 23 '07 #2
SAL
Hi Walter and thanks for your reply. I used the code you posted as a
template for the partial class but I'm not getting any data to update even
though the correct values are getting set in a DataTable and being passed
into my UpdateBatchCnty AssetsAssetMana gement function shown below. I'm also
posting the code for the partial class. The Update method being called in my
Business class was generated by the designer.

I'm posting my business logic layer class here:

Imports Microsoft.Visua lBasic
Imports System.Data.Sql Client
Imports System.Data
Imports CatsDsTableAdap ters

<System.Compone ntModel.DataObj ect()_
Public Class CntyAssetsAsset ManagementBLL
Private caamTa As CntyAssetsAsset ManagementTable Adapter

Protected ReadOnly Property Adapter() As
CntyAssetsAsset ManagementTable Adapter
Get
If caamTa Is Nothing Then
caamTa = New CntyAssetsAsset ManagementTable Adapter
End If
Return caamTa
End Get
End Property

<System.Compone ntModel.DataObj ectMethodAttrib ute(System.Comp onentModel.Data ObjectMethodTyp e.Select,
True)_
Public Function GetCntyAssetsAs setManagement() As
CatsDs.CntyAsse tsAssetManageme ntDataTable
Return Adapter.GetCnty AssetsAssetMana gement()
End Function

<System.Compone ntModel.DataObj ectMethodAttrib ute(System.Comp onentModel.Data ObjectMethodTyp e.Select,
False)_
Public Function GetCntyAssetsAs setManagement(B yVal whereClause As String)
As CatsDs.CntyAsse tsAssetManageme ntDataTable
Adapter.UpdateW here(whereClaus e)
Return Adapter.GetCnty AssetsAssetMana gement()
End Function

<System.Compone ntModel.DataObj ectMethodAttrib ute(System.Comp onentModel.Data ObjectMethodTyp e.Select,
False)_
Public Function GetCntyAssetByA ssetId(ByVal aid As Integer) As
CatsDs.CntyAsse tsAssetManageme ntDataTable
Return Adapter.GetCnty AssetByAssetId( aid)
End Function

<System.Compone ntModel.DataObj ectMethodAttrib ute(System.Comp onentModel.Data ObjectMethodTyp e.Update,
True)_
Public Function UpdateBatchCnty AssetsAssetMana gement(ByVal caamdt As
CatsDs.CntyAsse tsAssetManageme ntDataTable) As Boolean
For Each dr As CatsDs.CntyAsse tsAssetManageme ntRow In caamdt.Rows
If Not dr.IsAssetNumbe rNull Then
dr.AssetReviewe d = True
End If
If Not dr.IsAssetNotTr ackedNull AndAlso dr.AssetNotTrac ked = True
Then
dr.AssetReviewe d = True
End If
If Not dr.IsNoLongerCn tyAssetNull AndAlso dr.NoLongerCnty Asset =
True Then
dr.DateAssetDro pped = Now
End If
Next
caamdt.AcceptCh anges()
Adapter.Update( caamdt)
Return True
End Function

Public Sub UpdateWhere(ByV al where As String)
Adapter.UpdateW here(where)
End Sub
End Class

Imports Microsoft.Visua lBasic
Imports System.Data
Imports System.Data.Sql Client

Namespace CatsDsTableAdap ters
Partial Public Class CntyAssetsAsset ManagementTable Adapter

Private mSelectCommand As String

Public Sub UpdateWhere(ByV al where As String)
Me.InitCommandC ollection()
If mSelectCommand = "" OrElse mSelectCommand = String.Empty Then
mSelectCommand = Me._commandColl ection(0).Comma ndText
End If
Dim sql As String

If where = "" Then
sql = ""
Else
sql = " WHERE " & where
End If
Me._commandColl ection(0).Comma ndText = mSelectCommand & sql
End Sub
End Class
End Namespace
""Walter Wang [MSFT]"" <wa****@online. microsoft.comwr ote in message
news:aN******** *****@TK2MSFTNG HUB02.phx.gbl.. .
Hi SAL,

When you said "and a BusinessLogic layer using classes", do you mean the
class generated by the DataSet designer or your own class? I'm asking this
since the generated TableAdapter partial class also has this attribute:

Global.System.C omponentModel.D ataObjectAttrib ute(true),

If you defined your own custom BusinessLogic class and applied the
DataObjectAttri bute, could you please post some of your code to show how
you're using the TableAdapter?

Based on my understanding so far, you can create a partial class to the
TableAdapter and expose a public method or property to change the
CommandText of the select query to include your where clause. For example:

Namespace DataSet1TableAd apters
Partial Public Class authorsTableAda pter

Public Sub SetWhereClause( ByVal clause As String)
Me.InitCommandC ollection()
Me._commandColl ection(0).Comma ndText += " where " + clause
End Sub

End Class
End Namespace
Dim x As New DataSet1TableAd apters.authorsT ableAdapter
Dim ds As DataSet1.author sDataTable
x.SetWhereClaus e("phone like '4%'")
ds = x.GetData()
Hope this helps.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Oct 23 '07 #3
Hi SAL,

Thanks for your quick reply.

I'm not very clear about your follow-up question, let me verify some points
first:

1) Our first question is talking about modifying the Select query to
return different data dynamically, is it working now?
2) Your follow-up question is about not being able to update the data,
right? If we remove the code that are adding the where clause, does it
work? Based on my understanding, what we have added is only to append some
where clause the the Select query only, it should not affect the updating
behavior.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 25 '07 #4
Hi SAL,

Would you please post a reply here to let me know the status of this post?
Thanks.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 30 '07 #5
SAL
I'm sorry Walter. I did get everything working fine. Thank you very much for
your help.
S

""Walter Wang [MSFT]"" <wa****@online. microsoft.comwr ote in message
news:gU******** *****@TK2MSFTNG HUB02.phx.gbl.. .
Hi SAL,

Would you please post a reply here to let me know the status of this post?
Thanks.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 14 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1849
by: Sebastian Sylvan | last post by:
Hey. I have two questions. First of all I'm using the Visual C# Express Beta. When you create a windows application it will automatically split the main form into two files using partial classes. In the solution explorer this is seen hierarchially as somthing like - MainForm.cs -> MainForm.Designer.cs
3
3917
by: Rene | last post by:
VS 2005 uses the Partial Class & <form>.Designer.cs for its windows forms generated code. When upgrading from 2003 the project wizard did not break the form, it left it the old way. I would like to split them. Who the heck do you do that? Other than using the IDE and add a new Form, I was not able to insert the partial Form class in the nice hierarchical way the IDE does it. How do you do that? Thanks.
2
1262
by: Billy | last post by:
In .Net 2, when I have created a strongly typed dataset of a SQL table and then 'viewed' the code from the RHM menu. I am taken to the new partial class; as expected, but why do I have a partial class within a partial? plus if I was to inherit an interface then what partial class should I place the interface on, the outer partial class or the inner partial class? Regards Billy
9
3261
by: TheSteph | last post by:
In VS 2005 Form files are in 3 parts : From1.cs, Form1.Designer.cs and Form1.resx. In VS 2003 there is only one ".cs files". How can I split my old VS2003 ".cs files" files in 2 files : From.cs and Form.Designer.cs, and get thoses file "grouped" in the Solution explorer under the main Form.cs file ?
3
3184
by: erich | last post by:
In VS2005, creating a new form creates the form class and a partial (frm*.designer.vb) class file and displays the partial class beneath the main form frm*.vb, which is great. However, when extracting the designer code elements from an existing form class into its own partial class, (or creating new ones) the partial class is displayed in the Solution Explorer under the Project name, that is, at the same level as the file from which it...
2
5560
by: Joseph Geretz | last post by:
When I create a Form, the VB IDE creates the following files in the following hierarchy: Form1.cs Form1.Designer.cs Form1.resx Both Form1.cs and Form1.Designer.cs are partial implementations of a single physical class definition. The VB IDE properly recognizes Form1.cs as a Form (i.e. double-clicking opens the Form designer). It also recognizes
2
1721
by: Gary Brown | last post by:
Hi, I have moved some of the implementation of a form into a second file and enclosed it with "partial class ..." VS wants to give the second file its own designer form. How do I prevent that and how do I get rid of the second one? Thanks, Gary
2
2695
by: Peted | last post by:
im using c# vs2008 is it possible to define two partial classes in two different named code modules in this case the class and its attched designer class, and have a using statement at the top of the main class that allows access to a 3rd class/control/dll etc etc if i have the using statment at the top of the main class is it possible to have that using statement used in a partial class there, and have the using statment propogate...
2
2001
by: pihentagy | last post by:
Hi all! Is it possible to have a bindingsource in a partial class? Well it is possible, but I have the following issues: - this.components is defined in the .designer.cs file. If I call my own initialization method before the GUI's one, I will not have this.components. If I call it after, it's too late, because I'd like to bind it to a GUI component - my IDE (#develop) doesn't display my own partial class as part of the Form. What...
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
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
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
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...
1
6179
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
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
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.