Autor Beitrag
erfahrener Neuling
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 233
Erhaltene Danke: 19

Win 7, Win 10
C#, ASP-MVC (VS 2017 Community), MS SQL, Firebird SQL
BeitragVerfasst: Mo 02.05.16 12:18 
Hallo,

wie aus diesem Thread hier schon hervor ging, habe ich einen DataReader, welcher aus einem command erzeugt wurde und Daten ausließt.
Wenn ich die Werte nach Typ abfrage, funktioniert das auch. Nur wenn ich danach die DataRow ausgebe, sind diese Typen dann nicht mehr erhalten:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
using (FbDataReader reader = command.ExecuteReader(CommandBehavior.Default))
{
    while (reader.Read())
    {
        row = table.NewRow();
        for (int i = 0;i < reader.FieldCount;i++)
        {
            if (reader.GetValue(i) is DateTime)
                row[i.ToString()] = reader.GetDateTime(i);
            else if (reader.GetValue(i) is double)
                row[i.ToString()] = reader.GetDouble(i);
            else
                row[i.ToString()] = reader.GetValue(i);
    }
}
Die table besteht aus reader.FieldCount-Anzahl-Spalten, die von 0 beginnend durchnummeriert sind (deswegen row[i.ToString()).

Woran liegt es? Liegt es an den row-Eigenschaften oder an der Table oder woran???
Vielen Dank für eure Antworten
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mo 02.05.16 12:53 
Warum nimmst du einen FBDataReader um Daten in eine DataTable zu füllen (sieht für mich so aus als wäre table eine DataTable) und nicht einfach einen FbDataAdapter?

Für diesen Beitrag haben gedankt: erfahrener Neuling
erfahrener Neuling Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 233
Erhaltene Danke: 19

Win 7, Win 10
C#, ASP-MVC (VS 2017 Community), MS SQL, Firebird SQL
BeitragVerfasst: Mo 02.05.16 12:56 
Das hatte ich am Anfang auch probiert. Allerdings hab ich keinen weg gefunden, einen DataAdapter mit einem command zu verknüpfen.
Ich brauche nämlich diesen command
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
FbCommand command = connection.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = procedureName;
//Parameter hinzufügen, falls vorhanden
if (parameters != null)
    for (int i=0; i<parameters.GetLength(0); i++)
        command.Parameters.AddWithValue(parameters[i,0],parameters[i,1]);
erfahrener Neuling Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 233
Erhaltene Danke: 19

Win 7, Win 10
C#, ASP-MVC (VS 2017 Community), MS SQL, Firebird SQL
BeitragVerfasst: Mo 02.05.16 12:58 
Ok halt. Das geht ja doch, hatte scheinbar Tomaten auf den Augen :autsch:
erfahrener Neuling Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 233
Erhaltene Danke: 19

Win 7, Win 10
C#, ASP-MVC (VS 2017 Community), MS SQL, Firebird SQL
BeitragVerfasst: Mo 02.05.16 13:11 
EDIT: funzt doch alles
richtige Lösung:
ausblenden C#-Quelltext
1:
2:
FbDataAdapter adapter = new FbDataAdapter(command);
adapter.Fill(table);