» »

[c#] Cudna napaka pri vpisu vrstice (row) v bazo

[c#] Cudna napaka pri vpisu vrstice (row) v bazo

KernelPanic ::

Spostovani!

Spet bi rabil pomoc, in sicer pri sledeci kodi:
        void saveParametersToDatabase()
        {
            System.Console.WriteLine("Entering saveParametersToDatabase()");    // test code

            DataRow drStatusTargetRow;
            float fNumber = 0;
            bool bOk = false;
            int iNumberOfRows = this.m_datasetPinus.ACCULOAD_STATUS.Count;
            UInt32 iValue = 0;

            if (iNumberOfRows > 0)
            {
                // table is not empty, access 0-th record, alter it and save it back to db table

                drStatusTargetRow = this.m_datasetPinus.ACCULOAD_STATUS.Rows[0];
            }
            else
            {
                // table is empty, add a record

                drStatusTargetRow = this.m_datasetPinus.ACCULOAD_STATUS.NewRow();
            }   // if

            // **** TRANSFER VALUES TO RECORD
            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_SLAVE_ADDRESS] = this.m_aiAcculoadIIISlaveAddresses[0];

            bOk = this.m_CoreFunctions[0].readFlowRateAverage(ref fNumber);
            if (!bOk)
                fNumber = 0;
            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_FLOW_RATE_AVERAGE] = fNumber;

            bOk = this.m_CoreFunctions[0].readTemperature(ref fNumber);
            if (!bOk)
                fNumber = 0;
            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_TEMPERATURE] = fNumber;

            bOk = this.m_CoreFunctions[0].readPresetVolume(ref iValue);
            if (!bOk)
                fNumber = 0;
            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_PRESET] = iValue;

            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_ARM_PARKED] = this.m_ssDigitalIO5.m_bState;
            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_GROUNDING] = this.m_ssDigitalIO7.m_bState;
            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_OVERFILL] = this.m_ssDigitalIO1.m_bState;
            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_CONDITIONS_PLC] = this.m_ssDigitalIO9.m_bState;
            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_ESD] = this.m_ssDigitalIO4.m_bState;
            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_ALARM_PRESENT] = this.m_bwParams.m_bAlarmCondition;
            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_PRODUCT_FLOWING] = this.m_ssProductFlowing.m_bState;

            drStatusTargetRow[AccuLoadIIIMonitor.TableStatus.FieldNames.
                FIELD_TIMESTAMP] = DateTime.Now;    // saves timestamp
            // **** END OF TRANSFER VALUES TO RECORD

            if (iNumberOfRows > 0)
            {
                // table is not empty, save changed in SAME row
                int iRowsAffected = this.m_taStatus.Update(this.m_datasetPinus);
            }
            else
            {
                // table empty, save now row
                this.m_datasetPinus.ACCULOAD_STATUS.Rows.Add(drStatusTargetRow);
            }
            this.m_datasetPinus.ACCULOAD_STATUS.AcceptChanges();

            System.Console.WriteLine("Exiting saveParametersToDatabase()");    // test code
        }   // saveParametersToDatabase()
Namrec, naloga je, da tabela vsebuje le en record (prebrani podatki iz naprave), zato funkcija preveri, ce je tabela prazna, vstavi nov record, ce ni prazna, spremeni 0-ti record in ga nazaj shrani v tabelo. Vendar se zgodi sledece:
1) Ce tabelo izpraznim na serverju, se izvede stavek
                // table empty, save now row
                this.m_datasetPinus.ACCULOAD_STATUS.Rows.Add(drStatusTargetRow);
in nato AcceptChanges(), kar je ok, vendar zapisa ni v tabeli.
2) Ce tabela ze vsebuje record, se izvede stavek
                // table is not empty, save changed in SAME row
                int iRowsAffected = this.m_taStatus.Update(this.m_datasetPinus);
in nato spet AcceptChanges(), vendar tu v konzoli pride do sledece napake:
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Step into: Stepping over method without symbols 'System.ComponentModel.BackgroundWorker.WorkerThreadStart'
Step into: Stepping over method without symbols 'System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage'
Step into: Stepping over method without symbols 'System.Threading.ThreadPoolWorkQueue.Dispatch'
Mi lahko kdo pomaga prosim???


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[c#] Vprasanje glede eventov

Oddelek: Programiranje
101416 (1130) Looooooka
»

c# - mssql kombinacija / problem pri zapisu row-a v bazo

Oddelek: Programiranje
121623 (1432) darkolord
»

[c#] Vprasanje glede BackGroundWorker classa in spreminanja gui elementa

Oddelek: Programiranje
6798 (724) Ericssony
»

[c#] Vprašanje glede release verzije aplikacije

Oddelek: Programiranje
51516 (1340) Ericssony
»

Tezava pri instanciranju class-a

Oddelek: Programiranje
61316 (1187) KernelPanic

Več podobnih tem