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.

Access 2007 SELECT @@IDENTITY

Empfohlene Antworten

Veröffentlicht

Hallo

ich möchte gerne in eine Access 2007 Datenbank neue Werte einfügen und dabei die ID aus einem Inkrement feld zurückbekommen. Ich will dafür c# benutzen. Hab jetzt schon ewig das Internet durchwühlt aber ich kriege das nicht hin. Mein Ansatz ist folgender: (Provider ist: Microsoft.ACE.OLEDB.12.0)

Es werden 20 Kunden eingefügt (das funktioniert auch) und es soll immer die Id zurückgegeben werden. Die ID ist aber immer 0!?

        

private void button1_Click(object sender, EventArgs e)

        {

            lblErg.Text = "";

            string connectionString = "Provider=" + txtProvider.Text + ";Data Source=" + txtDatenbank.Text + ";Persist Security Info=False;";


            using (OleDbConnection connection = new OleDbConnection(connectionString))

            {

                OleDbCommand command = new OleDbCommand();

                OleDbTransaction transaction = null;


                command.Connection = connection;


                try

                {

                    connection.Open();


                    transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);


                    command.Connection = connection;

                    command.Transaction = transaction;


                    for (int i = 1; i <= 20; i++)

                    {

                        command.CommandText = "Insert Into Kunden (Kurzname) Values ('TestIdent " + i.ToString() + "')";

                        command.ExecuteNonQuery();

                        command.CommandText = "SELECT @@IDENTITY";

                        lblErg.Text += command.ExecuteScalar().ToString();

                    }


                    transaction.Commit();

                }

                catch (Exception ex)

                {

                }

            }

        }

Über eine Idee würde ich mich sehr freuen. :)

Bearbeitet von Timmbo

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.