Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

DataReader: Auslesen von int

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

eine ganz kurze Frage. Sicherlich ist die Lösung ganz einfach, aber ich komme einfach nicht drauf:

Das besagte Feld ist ein ID - Feld in der Datenbank, auch in meinem Objekt ist es ein int Attribut. Nun möchte ich es aus meinem DataReader auslesen und in das Attribut schreiben, was nicht geht...


private int hisNr;


.....


if (reader != null)

{

int nrColumnIndex = reader.GetOrdinal("cst_name_id");


    while (reader.Read())

    {   

    ......

    currentUser.Nummer = reader.GetInt32(nrColumnIndex);

    }

}



....


        public int Nummer

        {

            get

            {

                return hisNr;

            }

            set

            {

                hisNr = value;

            }

        }

Wie muss ich das korrekt auslesen? Das gleiche Problem hab ich auf bei nem Wert in (0 oder 1) und nem bool - Wert in meinem Objekt.

Gruß

Mathias

Es gibt zwei Möglichkeiten an den Wert zu kommen.


int ordinal = dataReader.GetOrdinal(columnName);

(T) dataReader.GetValue(ordinal); // Wobei T Dein Datentyp sein kann.

oder

object obj2 = reader[columnName]; // Wobei Du hier auf Int32 casten kannst.

Granate... Ich habs immer mit (Int32) und nicht mit (Int) versucht. nun klappt es. Danke

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.