Documents on MDI forms with Dataset?

  • Thread starter Thread starter al
  • Start date Start date
A

al

Greetings,

Thanks in advance for your kind attension.

I have been searching for documents about dynamically coding MDI forms
when working with datasets. Does anyone know of any???

MTIA,
Grawsha
 
al said:
I have been searching for documents about dynamically coding MDI
forms when working with datasets. Does anyone know of any???

Apart from <F1> I don't know any documents. ;-)

Do you have a specific question? Maybe I can help.
 
Armin Zingler said:
Apart from <F1> I don't know any documents. ;-)

Do you have a specific question? Maybe I can help.

I basically look for a way to avoid hard coding column names in the
SQL statement when I send changes (delete,udate and insert) back to
the database(i'm still working on the logical development. of the
app). The case is like thsi: I have a MDI form with a couple of
children forms(employees and customers). The related datatables(dt) in
the dataset(ds) is filled from database when its related form is
first loaded(table customer is filled when form customer is first
loaded). I refer to AciveMdiChild.Text in the MDI parent to load that
child form.

User, say, deletes a record by clicking a button to send the changes
to the database. There will be one button (on the toolbar of MDI
parent)for each operation (delet, update and insert). Now, my
problem comes when I try to write the SQL statement to send changes
back to database. That is, I don't want to hard code the column name
like this:

Dim str as String="Delete from employees where employeeID=@employeeid"

This will force me to write another SQL stat. for the the customers
form, which I do not want to do.

In this string, I was able to substitute the table name with the
ActiveMdiChilde.Text property. Now, to substitue the column name, I
look at the location of the related column name in the underlyning
datatable in the dataset, but the problem this column(usually Primary
Key,PK) does not have fixed location(it might be col 0 in one
employees table but col 1 in customers table ) or it might be 2
columns in some cases.

This is still hard coding the location of the column name:

Dim str as String="Delete from" & ActiveMdiChild.Text & " where " &
ds.tables _(ActiveMdiChild.Text).Columns(0).ColumnName & "=@" &
ds.tables _(ActiveMdiChild.Text).Columns(0).ColumnName

How should I DYNAMICALL refer to the location of the column name in
the underlyning datatable??
Should I use class or interface or what??? Remember, the
ActiveMdiChild is a basic form with basic properties,i.e., I can't
refer to labels or textboxes of the child form. ONLY names,text,etc..

MTIA,
Grawsha
 
Hi Al,

A dataset is never doing things with the MDI form direct but always with
controls placed on it, which can interact with dataset.

Therefore I do not see why there should be an answer for your question, can
you explain it something more?

Cor
 
al said:
Apart from <F1> I don't know any documents. ;-)

Do you have a specific question? Maybe I can help.

[...]
How should I DYNAMICALL refer to the location of the column name
in the underlyning datatable??
Should I use class or interface or what??? Remember, the
ActiveMdiChild is a basic form with basic properties,i.e., I can't
refer to labels or textboxes of the child form. ONLY
names,text,etc..

I don't think there is a short answer that explains the details. I can only
give a general answer: I'd store the information on a table somewhere and
pass it to each child. How this can be done is an individual design
question - and I'm usually getting paid for more details. ;-) If you've got
all information about the structure of the table in a DataTable, you can
dynamically built the Form, the SQL and whatever, based on this information.
For example, you can use a loop to process all columns, to build the SQL
string and to fill the Parameters. If you use a Commandbuilder, it's
(usually) sufficient to build the select string and the other SQL strings
(update/delete) are built for you.
 
Cor said:
Hi Al,

A dataset is never doing things with the MDI form direct but always with
controls placed on it, which can interact with dataset.

Therefore I do not see why there should be an answer for your question, can
you explain it something more?

Cor


Hello Cor,

The basic delma i'm facing comes from two sides. One is User
Interface (UI) requirments and second to be effeciant with coding.
For the first part, there is supposed to be only one button(on toolbar
of the MDI parent) for each database operation. One button to do only
one job(button for update, another for insert and third for delete),
so that both forms use it, or for as many forms as needed, for this
matter. This leads to the second part of the problem. That is, say a
user clicks the delete button, this forces me to have IF condition to
test for the ActiveMdiChild and see which of the children forms is
active. This way I will have to hard code for all of the children
forms. I don't want to that!
Now, having said that, I want to be more specific to get the "big
picture".
With the delete operation , for example,I use SQL statement to send
chagnes to DB.

"Delete from employees where employeeid=@employeeid"

If I do something like this, then i have to do it for all child forms.
What I want is to write ONE delete statement for all forms, i.e.,
DYANMIC one.
I was able to produce the following to get ONE dynamic SQL statement
for All child forms:

NOTE:
******************************************************************************
ActiveMdiChild.Text reads the child form's TEXT property, which is the
same as the table name in the dataset,i.e., customers form has
CUSTOMERS name as its text
*******************************************************************************

IF Me.Toolbar.button.text = "Delete" Then

"Delete from" & ActiveMdiChild.Text & " where" & ds.tables
(ActiveMdiChild.Text).Columns(0).ColumnName & "=@" &
ActiMdiChi.Text.Column (0).ColumnName

End If

Here, I don' know how to create the dyanmic column location, instead
of hardcoding the location to 0.


Grawsha
 
Hi Al,

I type it in here not in the designer so check it good

I have still to asume a lot but I see you use a dataset, I start asuming
that you use datagrids or something and that you want to delete a row from a
dataset from which you know the dataset row.

I think you can than use a shared class for this
\\\
public class Al
public shared sub AlsDelete(byval ds as dataset, byval tabl as string,
byval row as integer)
ds.tables(tabl).rows(row).delete
end sub
end class
///
And then when you want to delete a row
\\\
IF Me.Toolbar.button.text = "Delete" Then
Al.alsdelete(ds,"ActiveMdiChild",rowposition)
End If
///
You can give it a try.

Cor
 
Back
Top