473,803 Members | 3,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inheiritance of a from WITH a dataset

I have jumped in to the deep end of the pool, trying out visual inheritance
of a form and have run into a snag.

I have the need to create a simple maintenance form for five identically
configured database files. (The only difference in the tables is their name
and keyfield name.) Hmmm, I though, a perfect candidate for trying our
Visual Inheritance for the first time. ARGHHHHHHH! What have I gotten
myself into?

Here's the specifics. I created a form and saved it as a class. I am able
to then create a form that inherits my original. That part works great. I
was even able to add a couple of Protected Strings to the base form and in
the Public Sub New routine of the one of the real forms I added code to set
the two protected strings to reflect the Table name and Key name. The form
load event in the base form uses these strings to dynamically create the SQL
Data adapters SQLSelectComman d, the SQLEditCommand, SQLInsertComman d etc. I
even got the base form code to modify the BindingContext so the update and
inserts worked flawlessly.

The base form has a dataset defined on it. I was HOPING to modify the code
for the dataset so that I could use the same Table Name and Key Name fields
to dynamically create the dataset like I was able to do with the
SqlDataAdapter' s command strings. My real form inherits the base form,
initializes a base form instance and then sets my two protected strings in
the base form. Thusly:

Public Class frmIOClass
Inherits TheClassForm.fr mTheClass

#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
'*gs* These override the Protected strings in the base class
' of this form.

MyClass.strTheT able = "Input_Output_C lass"
MyClass.strTheK ey = "IOClass"
End Sub

Then in the load event of the baseform the code executes to generate the
SQLDataAdapter command strings. I tried putting code in the load event that
would populate some Protected strings in the dataset class code module. But
I soon realized that was WAY too late. The initialization code for the
dataset class was executed when the base form itself was initialized. It
was at that time that the dataset class was instantiated.

I'm stumped. I can't figure out how to get the Private strings set with the
Table Name and Key Name in the dataset class code BEFORE the dataset class
initialization code executes. I found the code in the base form that
actually instantiates the dataset. Here is a bit of that code:
Friend WithEvents dsTheClass As TheClassForm.ds TheClass
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

Dim resources As System.Resource s.ResourceManag er = New
System.Resource s.ResourceManag er(GetType(frmT heClass))
Me.txtTheClassN ame = New System.Windows. Forms.TextBox
Me.dsTheClass = New TheClassForm.ds TheClass
Me.txtTheClassD escription = New System.Windows. Forms.TextBox
Me.btnCancel = New System.Windows. Forms.Button
Me.btnOK = New System.Windows. Forms.Button
Me.SqlDataAdapt er1 = New System.Data.Sql Client.SqlDataA dapter
Me.SqlDeleteCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlInsertCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlUpdateCom mand1 = New System.Data.Sql Client.SqlComma nd
CType(Me.dsTheC lass, System.Componen tModel.ISupport Initialize).Beg inInit()

I thought I could sneak in the code to set some private strings in the
dataset class right after the "Me.dsclass = New TheClassForm.ds Class" line
of code, but apparently VB wasn't kidding when I read the comment in the
code admonishing me as follows:

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.

Any code I try to add there gets "eaten" by the IDE. So I've hit the
proverbial brick wall. Anybody tried to tackle this before? Anyone have
any pearls of wisdom that they might share on this topic?

Thanks,

Gary Shell


Nov 20 '05 #1
2 1172
If ever a wizard there was !, Wizards can help or hinder !

On the base form, take out all that code generated by the Visual Designer
and put it into a helper function. Delete the visual elements and do the
coding from scratch. Test your base form.

Arrange for this function to accept parameters you need to alter the
initialisation.

Now in your constructor for the subclass'ed form, call your helper function
to set up the appropriate table values etc

HTH
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Gary Shell" <gs****@fuse.ne t> wrote in message
news:u2******** ******@TK2MSFTN GP12.phx.gbl...
I have jumped in to the deep end of the pool, trying out visual inheritance of a form and have run into a snag.

I have the need to create a simple maintenance form for five identically
configured database files. (The only difference in the tables is their name and keyfield name.) Hmmm, I though, a perfect candidate for trying our
Visual Inheritance for the first time. ARGHHHHHHH! What have I gotten
myself into?

Here's the specifics. I created a form and saved it as a class. I am able to then create a form that inherits my original. That part works great. I was even able to add a couple of Protected Strings to the base form and in
the Public Sub New routine of the one of the real forms I added code to set the two protected strings to reflect the Table name and Key name. The form load event in the base form uses these strings to dynamically create the SQL Data adapters SQLSelectComman d, the SQLEditCommand, SQLInsertComman d etc. I even got the base form code to modify the BindingContext so the update and
inserts worked flawlessly.

The base form has a dataset defined on it. I was HOPING to modify the code for the dataset so that I could use the same Table Name and Key Name fields to dynamically create the dataset like I was able to do with the
SqlDataAdapter' s command strings. My real form inherits the base form,
initializes a base form instance and then sets my two protected strings in
the base form. Thusly:

Public Class frmIOClass
Inherits TheClassForm.fr mTheClass

#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
'*gs* These override the Protected strings in the base class
' of this form.

MyClass.strTheT able = "Input_Output_C lass"
MyClass.strTheK ey = "IOClass"
End Sub

Then in the load event of the baseform the code executes to generate the
SQLDataAdapter command strings. I tried putting code in the load event that would populate some Protected strings in the dataset class code module. But I soon realized that was WAY too late. The initialization code for the
dataset class was executed when the base form itself was initialized. It
was at that time that the dataset class was instantiated.

I'm stumped. I can't figure out how to get the Private strings set with the Table Name and Key Name in the dataset class code BEFORE the dataset class
initialization code executes. I found the code in the base form that
actually instantiates the dataset. Here is a bit of that code:
Friend WithEvents dsTheClass As TheClassForm.ds TheClass
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
Dim resources As System.Resource s.ResourceManag er = New
System.Resource s.ResourceManag er(GetType(frmT heClass))
Me.txtTheClassN ame = New System.Windows. Forms.TextBox
Me.dsTheClass = New TheClassForm.ds TheClass
Me.txtTheClassD escription = New System.Windows. Forms.TextBox
Me.btnCancel = New System.Windows. Forms.Button
Me.btnOK = New System.Windows. Forms.Button
Me.SqlDataAdapt er1 = New System.Data.Sql Client.SqlDataA dapter
Me.SqlDeleteCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlInsertCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlUpdateCom mand1 = New System.Data.Sql Client.SqlComma nd
CType(Me.dsTheC lass, System.Componen tModel.ISupport Initialize).Beg inInit()

I thought I could sneak in the code to set some private strings in the
dataset class right after the "Me.dsclass = New TheClassForm.ds Class" line
of code, but apparently VB wasn't kidding when I read the comment in the
code admonishing me as follows:

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.

Any code I try to add there gets "eaten" by the IDE. So I've hit the
proverbial brick wall. Anybody tried to tackle this before? Anyone have
any pearls of wisdom that they might share on this topic?

Thanks,

Gary Shell

Nov 20 '05 #2
Hi Gary,

I think that you can get what you want this when you are not using a typed
dataset as you do.
That typed dataset is set as class in your project.
You can see it when you set in the solution explorer to all files and push
on the +'s
That dataset class is generated from the XSD in design time and uses table
and datanames.
I think that it is therefore almost impossible to reach what you want.

However just my thougth.

Cor
I have jumped in to the deep end of the pool, trying out visual inheritance of a form and have run into a snag.

I have the need to create a simple maintenance form for five identically
configured database files. (The only difference in the tables is their name and keyfield name.) Hmmm, I though, a perfect candidate for trying our
Visual Inheritance for the first time. ARGHHHHHHH! What have I gotten
myself into?

Here's the specifics. I created a form and saved it as a class. I am able to then create a form that inherits my original. That part works great. I was even able to add a couple of Protected Strings to the base form and in
the Public Sub New routine of the one of the real forms I added code to set the two protected strings to reflect the Table name and Key name. The form load event in the base form uses these strings to dynamically create the SQL Data adapters SQLSelectComman d, the SQLEditCommand, SQLInsertComman d etc. I even got the base form code to modify the BindingContext so the update and
inserts worked flawlessly.

The base form has a dataset defined on it. I was HOPING to modify the code for the dataset so that I could use the same Table Name and Key Name fields to dynamically create the dataset like I was able to do with the
SqlDataAdapter' s command strings. My real form inherits the base form,
initializes a base form instance and then sets my two protected strings in
the base form. Thusly:

Public Class frmIOClass
Inherits TheClassForm.fr mTheClass

#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
'*gs* These override the Protected strings in the base class
' of this form.

MyClass.strTheT able = "Input_Output_C lass"
MyClass.strTheK ey = "IOClass"
End Sub

Then in the load event of the baseform the code executes to generate the
SQLDataAdapter command strings. I tried putting code in the load event that would populate some Protected strings in the dataset class code module. But I soon realized that was WAY too late. The initialization code for the
dataset class was executed when the base form itself was initialized. It
was at that time that the dataset class was instantiated.

I'm stumped. I can't figure out how to get the Private strings set with the Table Name and Key Name in the dataset class code BEFORE the dataset class
initialization code executes. I found the code in the base form that
actually instantiates the dataset. Here is a bit of that code:
Friend WithEvents dsTheClass As TheClassForm.ds TheClass
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
Dim resources As System.Resource s.ResourceManag er = New
System.Resource s.ResourceManag er(GetType(frmT heClass))
Me.txtTheClassN ame = New System.Windows. Forms.TextBox
Me.dsTheClass = New TheClassForm.ds TheClass
Me.txtTheClassD escription = New System.Windows. Forms.TextBox
Me.btnCancel = New System.Windows. Forms.Button
Me.btnOK = New System.Windows. Forms.Button
Me.SqlDataAdapt er1 = New System.Data.Sql Client.SqlDataA dapter
Me.SqlDeleteCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlInsertCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd
Me.SqlUpdateCom mand1 = New System.Data.Sql Client.SqlComma nd
CType(Me.dsTheC lass, System.Componen tModel.ISupport Initialize).Beg inInit()

I thought I could sneak in the code to set some private strings in the
dataset class right after the "Me.dsclass = New TheClassForm.ds Class" line
of code, but apparently VB wasn't kidding when I read the comment in the
code admonishing me as follows:

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.

Any code I try to add there gets "eaten" by the IDE. So I've hit the
proverbial brick wall. Anybody tried to tackle this before? Anyone have
any pearls of wisdom that they might share on this topic?

Thanks,

Gary Shell

Nov 20 '05 #3

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

Similar topics

4
555
by: Simon | last post by:
Hi all, I have a process, where I take a dataset from an SQL call, and need to write an XML file from that dataset. The data set can contain 10's of tables, each with 100's of rows, and I have no way of knowing what the tables are, or what they contain. I am currently using the Dataset.WriteXML method passing an XMLWriter.
3
6602
by: Jeronimo Bertran | last post by:
Hi, I have an xml file that encapsulates a dataset definition within a set of tags (<dataset>)... here is an example <?xml version="1.0" encoding="utf-16"?> <dataset> <MyTable> <Field1>100</Field1> <Field2>200</Field2>
5
5413
by: Mike | last post by:
I need to expand the DataSet class by inheriting from it and adding functions that work on the data in the tables. However, since I can't upcast how can I get my base DataSet object assigned an actual DataSet? e.g. public class MyDataSet : DataSet { // can't do, no valid DataSet constructor
7
6235
by: Sharon | last post by:
I have successfully loaded a DataSet object with a XML schema (XSD). Now I wish to populate the tables that was created in the DataSet. I have an XML file/string that contain all the needed data in the same format as the XSD (the XML file/string was created using this same schema). The XML file/string may contain data for a single table or for several tables at once. The question is:
6
5075
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which command do I use to update the changes in dataset back to the Access database table? Thanks, Alpha...
5
3704
by: Jason | last post by:
I am having problems understanding how to access a datasource only once, fill a single dataset, and then reference that dataset multiple times through different user controls(ascx) found on the same page. My main page(aspx) contains multiple user controls. The main page also contains a publicly declared dataset. At the first instance of needing data I call (from an ascx) a function that fills the dataset and then returns it to the...
0
3169
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these datacolumns do not trigger their expression when other columns from which the expressions are derived are updated. Below is a basic example of what I am doing. User enters values into an asp.net form and clicks a button. Retrieve dataset from...
2
6971
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
3
2847
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one dataset to data in a second dataset, using a common key. I will first describe the problem in words and then I will show my code, which has most of the solution done already. I have built an ASP.NET that queries an Index Server and returns a...
0
9700
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
10310
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
10292
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
10068
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
9121
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
7603
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
6841
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
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
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.