Autor Beitrag
gerhard_68
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Sa 20.11.10 12:55 
Hallo,

Ich habe 3 Tabellen und möchte die Zeitdifferenz berechen. Ich verwende Visual Studio c#.

tbl_anfang -> 12.11.2010 8:30:00
tbl_ende -> 12.11.2010 16:15:00

tbl_gesamt soll die Zeit stehen 7:45

Die Daten stehen im dataGridView1 und werden nach der berechnung in eine Acess Datenbank (Update) retour geschrieben.

Vieleicht hat jemand einen Mustercode oder einen Ansatz für die Lösung (DateTime usw.)

LG

Gerhard
gerhard_68 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Sa 20.11.10 13:32 
Die Berechnung habe ich, jetzt soll das Ganze mit den Tabellen funktionieren.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
string s, t;

s = textBox2.Text;
t = textBox3.Text;

DateTime dt3 = DateTime.Parse(s);
DateTime dt4 = DateTime.Parse(t);

TimeSpan re;
re = dt4 - dt3;
textBox1.Text = re.ToString();


Moderiert von user profile iconKha: C#-Tags hinzugefügt
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Sa 20.11.10 18:27 
user profile icongerhard_68 hat folgendes geschrieben Zum zitierten Posting springen:
Die Berechnung habe ich, jetzt soll das Ganze mit den Tabellen funktionieren.

Wo liegt das Problem? Beim Erstellen der Update-Query? Erwartet die Datenbank ein anderes Format als das von TimeSpan.ToString verwendete? Oder ist mein Beitrag sinnlos, weil du es schon geschafft hast?
gerhard_68 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: So 21.11.10 12:42 
Hallo,

erstmal Danke für die Antwort. Leider habe ich noch keine Ahnung wie die gesamte Spalte tbl_gesamt berechnet wird.
gerhard_68 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: So 21.11.10 15:29 
Hallo,

habe folgendes im Abfragegenerator probiert.( Visual08 c#)

INSERT INTO zeiterfassung
(tbl_gesamt)


VALUES (DatDiff('n', tbl_anfang, tbl_ende) / 60)

Fehlerquelle: MS Access DataBase Engine
Meldung: Undefinierte Funktion DatDiff im Ausdruck

Aber in Access unter Abfragen funtioniert es !

Vielleicht hat noch jemand einen Vorschlag bzw.einen Code.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 21.11.10 16:07 
user profile icongerhard_68 hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden SQL-Anweisung
1:
2:
3:
INSERT INTO zeiterfassung
(tbl_gesamt)
VALUES (DatDiff('n', tbl_anfang, tbl_ende) / 60)

Bist du dir sicher, dass die Funktion DatDiff, und nicht etwa DATEDIFF heißt? Im MSDN ist letztere dokumentiert.
gerhard_68 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mo 22.11.10 11:31 
SELECT DateDiff('n', Dat_Zeit_Beginn, Dat_Zeit_Ende) / 60 AS Dat_Endzeit
FROM tbl_Zeiterfassung

Die Abfrage funktioniert im Abfrage Generator jedoch bekomme ich folgende Meldung:

Das von der neuen Abfrage zurückgelieferte Schema weicht von der Basisabfrage ab.
Somit kann ich die Abfrage nicht verwenden
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mo 22.11.10 18:14 
Hilft dir vielleicht das erste Google-Ergebnis weiter? Oder ein anderes Suchergebnis?

Für diesen Beitrag haben gedankt: gerhard_68