Autor Beitrag
DennisXX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133



BeitragVerfasst: Mi 02.11.11 10:54 
Hallo zusammen,

Ich habe folgendes Problem: Ich habe eine Form bzw. Webform erstellt und sämtlichen Programmcode in die partielle Klasse ausgelagert, die Visual Studio mir erstellt hat, damit sich Gui Elemente und Programmlogik nicht vermischen und das Programm somit unübersichtlich wird.


Meine selbst erstellte C Sharp Klasse:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
namespace Dateneingabe
{
    public class MySQLDatabaseConnection
    {
        private Page formular;


        //Konstruktor
        public MySQLDatabaseConnection(Page formular)
        {
            this.formular = formular;
        }

        void irgendeineMethodeXYZ(string text)
        {
            formular.Label1Feld.Text = text; 

        } 

     }
}



Die von Visual Studio erstellte Partielle Klasse:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
namespace Dateneingabe
{
    public partial class Formular : System.Web.UI.Page
    {
        private MySQLDatabaseConnection mysqldatabaseconnection;        
        
        public Formular()
        {
            this.mysqldatabaseconnection = new MySQLDatabaseConnection(this);
            this.mysqldatabaseconnection.irgendeineMethodeXYZ(ABC);
        }
 
     }
}


Ich erhalte folgende Fehlermeldung beim Kompilieren:

private MySQLDatabaseConnection mysqldatabaseconnection; ist nicht vorhanden, evtl. fehlt eine using Direktive oder Assemblyverweis

Bei der Zeile formular.Label1Feld.Text = text; kann ich nicht kompilieren, da Label1Feld nicht erkannt wird.

Ich verstehe diese Fehlemeldungen nicht so wirklich.


Grüße
Dennis
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4799
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 02.11.11 11:26 
Hallo Dennis,

du hast ja auch nur "Page" anstatt "Formular" bei deiner MySQLDatabaseConnection-Klasse angegeben...

Es ist aber kein gutes Design, wenn eine Datenbankzugriffsklasse direkt auf Forms (bzw. Pages) zugreift.
DennisXX Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133



BeitragVerfasst: Mi 02.11.11 11:37 
Hallo !

Es ändert sich auch nichts an dem Problem, wenn ich "Formular" statt "Page" angebe.

Ob meine grundlegende Idee ein gutes Design ist oder nciht, sei erstmal dahingestellt. Für mich ist es zum Erlernen und Funktionieren von C Sharp erstmal ok.

Grüße
Dennis