Autor Beitrag
Talemantros
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Sa 22.03.14 15:59 
Hallo
ich habe über Visual Studio eine MDF erzeugt Optionen und darin eine tblOptionen mit 3 Feldern erzeugt.

NUn würde ich diese gern auslesen und aktualisieren können.
ICh möchte dies aber "von Hand" programmieren um auch zu verstehen und sehen was dahinter passiert. Und nicht über den Drag & Drop vom Visual Studio.

Leider sagt mein Prog dass die mdf Datei kein gültiges Datenbankdesign erkannt werden kann.
Hat jemand eine IDee für mich oder ein gutes Tutorial?

Die aktuellste VErsion (die aber auch nicht geht war:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
using System.Data.OleDb;

namespace rEcycle
{
    public partial class optionenSystem : Form
    {
        string connString = rEcycle.Properties.Settings.Default.optionenConnectionString;

        OleDbConnection conn = new OleDbConnection(connString);
        DataSet ds = new DataSet();
        OleDbCommand cmd = new OleDbCommand();

        public optionenSystem()
        {
            InitializeComponent();
        }

        private void btnSpeichern_Click(object sender, EventArgs e)
        {
            OleDbDataAdapter da = new OleDbDataAdapter("Select * from tblOptionen", conn);
            ds.Clear();
            cmd.Connection = conn;

            cmd.CommandText = "Update tblOptionen SET inhalt = 'TEST' where beschreibung 'pfadVorlagen'";

            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}


Vielen Dank

Gruß
Daniel

Edit:

Habe nun diesen Code und im SQL String noch ein = ergänzt

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
using System.Data.OleDb;

namespace rEcycle
{
    public partial class optionenSystem : Form
    {

        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Sourde=optionen.mdf;");
        DataSet ds = new DataSet();
        OleDbCommand cmd = new OleDbCommand();

        public optionenSystem()
        {
            InitializeComponent();
        }

        private void btnSpeichern_Click(object sender, EventArgs e)
        {
            OleDbDataAdapter da = new OleDbDataAdapter("Select * from tblOptionen", conn);
            ds.Clear();
            cmd.Connection = conn;

            cmd.CommandText = "Update tblOptionen SET inhalt = 'TEST' where beschreibung  = 'pfadVorlagen'";

            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}


Fehlermeldung:
Installierbares ISAM nicht gefunden
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Sa 22.03.14 17:12 
Hallo,

sofern das auch in deinem Code so steht
ausblenden C#-Quelltext
1:
"Data Sourde=optionen.mdf"					

statt "Data Source", ist die Fehlermeldung erklärbar.

Und ich weiß nicht, ob man dich schon auf die Verwendung von SQL-Parametern hingewiesen hat.

P.S. Dein erster Satz im Beitrag ist sehr schwer zu verstehen... Und die Groß-/Kleinschreibung bei dir auch verbesserungswürdig (aber kommt wahrscheinlich vom schnellen Tippen ;-)).
Talemantros Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Sa 22.03.14 17:29 
Hi TH69,
entschuldige bitte die Fehler durch die "schnelle" Anfrage.

Ich habe nun etliche Schnipsel probiert und bekomme immer wieder die Meldung

"Installierbares ISAM nicht gefunden"

Auch das Auslesen eines Wertes aus der DB (mittlerweile MDB in der Hoffnung es wäre besser) hat nicht funktioniert mit o.g. Meldung.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
            string connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=optionen.mdb;JET OLEDBatabase Password=****";
            OleDbConnection conn = new OleDbConnection(connStr);

            OleDbCommand cmd = new OleDbCommand("Select * from tblOptionen where id = 3");

            conn.Open();

            OleDbDataReader reader = cmd.ExecuteReader();

            txtPfadVorlagen.Text = reader["inhalt"].ToString();

            conn.Close();
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Sa 22.03.14 17:41 
Zitat:
ich habe über Visual Studio eine MDF erzeugt


Wie? So wie ich das kenne kommt da am Ende eine SQL Server Datenbank raus die man zum Beispiel über LocalDB ansprechen kann, aber es bleibt eine SQL Server DB wofür man die SQL Server Zugriffsklassen braucht und nicht OLEDB + Jet.

Edit: Was denn jetzt mdf oder mdb?


Zuletzt bearbeitet von Ralf Jansen am Sa 22.03.14 17:48, insgesamt 1-mal bearbeitet
Talemantros Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Sa 22.03.14 17:48 
Hi,
könntest du mir das mal in einen ConnectionString schreiben.
Ich bekomme es einfach nicht hin?!

Weiterhin würde mich interessieren was die Fehlermeldung bedeutet mit dem ISAM?!

Danke für eure Mühe

Gruß
Daniel
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Sa 22.03.14 17:52 
Zitat:
Weiterhin würde mich interessieren was die Fehlermeldung bedeutet mit dem ISAM?!


Jet kennt keine mdf. Jet ist insbesondere was für Office Formate von Word, Excel, Access etc. Die Fehlermeldung will dir sagen das Jet keinen ~Subtreiber~(oder wie man das auch immer nennen will) hat für das von dir angegebene Dateiformat.
Talemantros Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Sa 22.03.14 18:26 
Könnte mir jemand mal diesen Code

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
            string connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=optionen.mdb;JET OLEDBatabase Password=****";
            OleDbConnection conn = new OleDbConnection(connStr);

            OleDbCommand cmd = new OleDbCommand("Select * from tblOptionen where id = 3");

            conn.Open();

            OleDbDataReader reader = cmd.ExecuteReader();

            txtPfadVorlagen.Text = reader["inhalt"].ToString();

            conn.Close();


für die Nutzung an eine MDF anpassen?
Ich würde euch auch in mein Nachtgebet mit einschließen :-)

Danke

Gruß
Daniel

EDIT:
Jetzt habe ich eine Lösung.
Könnte mal jemand schauen, ob es da noch grobe Fehler gibt oder erst mal als Grundgerüst ok ist?

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
            string connStr = rEcycle.Properties.Settings.Default.optionenConnectionString;
            SqlConnection conn = new SqlConnection(connStr);

            conn.Open();
            using (SqlCommand command = new SqlCommand("SELECT * from tblOptionen WHERE id = 6", conn))
            {
                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    txtPfadVorlagen.Text = reader.GetString(2);                    
                }
            }
            conn.Close();


Was eine schwere Geburt :-)

Grüße
Daniel