User Control and DB

U

ucasesoftware

I have a panel and some userControls.
To load them to my Panel :

Dim monFormulaire As New UcFormulaireTest
panelFormulaire.Controls.Clear()
panelFormulaire.Controls.Add(monFormulaire)


But if i have a query who search the name of my UC :
like :
Dim monFormulaire As New cmd.executeScalar !!!! HERE IS MY PROBLEM
panelFormulaire.Controls.Clear()
panelFormulaire.Controls.Add(monFormulaire)

thx for help
 
C

Cor Ligthert [MVP]

Hi,
Dim monFormulaire As New cmd.executeScalar !!!! HERE IS MY PROBLEM

Have you any idea why this should work.

With this you tell that monFormulaire is a field in the correct format in a
database.
There is no usercontrol field at least in a SQLServer or MSAccess database.

Cor
 
U

ucasesoftware

Yes i know it... but i don't know how to convert to my type...

i try ctype... but i have not success
 
C

Cor Ligthert [MVP]

Usecasessoftware

Do you mean you want to do something in a kind of pseudo code

\\\
dim indexer as integer
"select indexer from database"
indexer = executescalar

select case indexer
case 1
pannel.add(usercontrol1)
case 2
pannel.add(usercontrol2)
end select
///

I hope this helps,

Cor
 
C

Cor Ligthert [MVP]

Unesec
dim myUC as new indexer

This command telss that there should be created a new object myUC from the
type indexer.

What is the sense of that?

Cor
 
U

ucasesoftware

no no
i have a userControl name : test.vb

in database i have a column : nameOfUserControl


with my cmd.executeScalar i read the column nameOfUserControl

so i want to do :

Dim monFormulaire As New cmd.executeScalar (who is "test")
 
U

ucasesoftware

myApplication have to take message from phone
But if its doctor message i have to display doctor UC and if it's
customers message i have to display curtomer message

So i have several UC and one message winform

but i can have 100 UC...
So ok i can do Select Case ....

but if i can do directry .... dim myUC as new " cmd.excecuteScalar"

it's more clean code...

that's all... but maybe it's impossible
 
C

Cor Ligthert [MVP]

ucase,

A control is not serializable, so you cannot place it in a database.
What you can do is giving it an ident.

Than you can find it direct in the method as I gave you, what is early
binding and which goes fast at runtime or using it indirect using reflection
(late binding).

For both you have to build an error routine in your program for if somebody
outside the program changes the database.

That reflection method is less work to type with 100 controls, however I
don't like it, with some copy and paste and simple indexnames that select is
as well very quick build.

Beneath a link to a sample. There are more samples in this newgroup about
using reflection with this. However you can maybe start with this one.

http://groups.google.com/group/microsoft.public.dotnet.languages.vb/msg/a3a8b431d53a4b7e?hl=en&

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top