473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 SQLSelectCommand, the SQLEditCommand, SQLInsertCommand 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.frmTheClass

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

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

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

MyClass.strTheTable = "Input_Output_Class"
MyClass.strTheKey = "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.dsTheClass
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(frmTheCla ss))
Me.txtTheClassName = New System.Windows.Forms.TextBox
Me.dsTheClass = New TheClassForm.dsTheClass
Me.txtTheClassDescription = New System.Windows.Forms.TextBox
Me.btnCancel = New System.Windows.Forms.Button
Me.btnOK = New System.Windows.Forms.Button
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
CType(Me.dsTheClass, System.ComponentModel.ISupportInitialize).BeginIni t()

I thought I could sneak in the code to set some private strings in the
dataset class right after the "Me.dsclass = New TheClassForm.dsClass" 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 1154
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.net> wrote in message
news:u2**************@TK2MSFTNGP12.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 SQLSelectCommand, the SQLEditCommand, SQLInsertCommand 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.frmTheClass

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

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

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

MyClass.strTheTable = "Input_Output_Class"
MyClass.strTheKey = "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.dsTheClass
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(frmTheCla ss))
Me.txtTheClassName = New System.Windows.Forms.TextBox
Me.dsTheClass = New TheClassForm.dsTheClass
Me.txtTheClassDescription = New System.Windows.Forms.TextBox
Me.btnCancel = New System.Windows.Forms.Button
Me.btnOK = New System.Windows.Forms.Button
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
CType(Me.dsTheClass, System.ComponentModel.ISupportInitialize).BeginIni t()

I thought I could sneak in the code to set some private strings in the
dataset class right after the "Me.dsclass = New TheClassForm.dsClass" 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 SQLSelectCommand, the SQLEditCommand, SQLInsertCommand 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.frmTheClass

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

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

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

MyClass.strTheTable = "Input_Output_Class"
MyClass.strTheKey = "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.dsTheClass
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(frmTheCla ss))
Me.txtTheClassName = New System.Windows.Forms.TextBox
Me.dsTheClass = New TheClassForm.dsTheClass
Me.txtTheClassDescription = New System.Windows.Forms.TextBox
Me.btnCancel = New System.Windows.Forms.Button
Me.btnOK = New System.Windows.Forms.Button
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
CType(Me.dsTheClass, System.ComponentModel.ISupportInitialize).BeginIni t()

I thought I could sneak in the code to set some private strings in the
dataset class right after the "Me.dsclass = New TheClassForm.dsClass" 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
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...
3
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>...
5
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...
7
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...
6
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...
5
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...
0
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...
2
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...
3
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.