Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

dataset.update problemi

[es] :: .NET :: dataset.update problemi

[ Pregleda: 2332 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

kopca

Član broj: 14307
Poruke: 118
*.88.eunet.yu.



Profil

icon dataset.update problemi11.02.2005. u 13:43 - pre 233 meseci
Code:

'class  ...  inherits windows.forms.datagrid 
Public Shadows Sub CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.CurrentCellChanged


        Dim tblStl As DataGridTableStyle = Me.GetCurrentTableStyle(Me.DataSourceTable.TableName.ToString)

        'setujemo zadnji pravac kretanja u gridu
        If (Me.LastCell.RowNumber <> Me.CurrentCell.RowNumber) And (Me.LastCell.ColumnNumber <> Me.CurrentCell.ColumnNumber) Then
            pLastMoveDirection = MoveDirection.UpDownLeftRight
        ElseIf (Me.LastCell.RowNumber <> Me.CurrentCell.RowNumber) Then
            pLastMoveDirection = MoveDirection.UpDown
        ElseIf (Me.LastCell.ColumnNumber <> Me.CurrentCell.ColumnNumber) Then
            pLastMoveDirection = MoveDirection.LeftRight
        ElseIf Me.LastCell.Equals(Me.CurrentCell) Then
            pLastMoveDirection = MoveDirection.ErrorMoveBack
        End If

        If TypeOf Me.DataSource Is DataView Then
            'kada je datasource - dataview ovog grida u stanju dodavanja novog reda, podešavamo stil datagrida da bude readonly, inače ne.


            If Me.DataSource.Item(Me.CurrentRowIndex).isNew Then
                If Not tblStl Is Nothing Then
                    tblStl.ReadOnly = True
                Else
                    MsgBox("CurrCellChangedUpdateDataGrid.CurrentCellChanged()" & vbCrLf & "Datagrid nema definisan 'DataGridTableStyle' sa mappingName = " & Me.DataSourceTable.TableName.ToString & vbCrLf & "Moguće greške u predvidjenom ponašanju datagrida.", MsgBoxStyle.Exclamation, "Exception")
                End If
                RaiseEvent Update_on_Current_Cell_Changed(Me.ErrorOnUpdate)
                Me.CurrentCell = Me.LastCell
                Exit Sub
            Else 'datasource je dataview, nismo u 'isnew' modu, vreme je za validaciju kolone i moguci update

                If Not ((Me.LastRowState Is Nothing) And (Me.LastColState Is Nothing)) Then
                    Select Case pLastMoveDirection
                        'krecemo se gridu gore-dole
                    Case MoveDirection.UpDown, MoveDirection.UpDownLeftRight
                            'menjali smo neki red
                            If (Not Me.LastRowState Is Nothing) Then
                                'poslednji menjani red nema gredaka
                                If Not Me.LastRowState.Row.HasErrors Then
                                    'dizemo dogadjaj za update baze
                                    RaiseEvent Update_on_Current_Cell_Changed(Me.ErrorOnUpdate)
                                    'ako se desila neka greska prilikom update-a, moramo da se vratimo na staru celiju
                                    'pogledati uputstvo za koriscenje ove klase na pocetku same klase vezano za update 
                                    If Me.ErrorOnUpdate Then
                                        Me.CurrentCell = Me.LastCell
                                        'dizemo dogadjaj za prijavljivanje greske prilikom update-a
                                        RaiseEvent Respond_On_Row_Update_Error(Me.ErrorOnUpdate)
                                        Exit Sub
                                    End If
                                Else 'zadnji menjani red ima gresku reda
                                    Me.CurrentCell = Me.LastCell
                                    'dizemo dogadjaj za prijavljivanje greske reda 
                                    RaiseEvent Respond_On_Row_Edit_Error(Me.LastRowState)
                                    Exit Sub
                                End If
                            End If

                        Case MoveDirection.LeftRight

                            ''ovaj if se koristi ukoliko se korisnik posle neuspesnog update-a vratio na staru celiju i seta se samo levo - desno.
                            'If Not Me.LastRowState Is Nothing Then
                            '    If Me.LastRowState.Row.HasErrors Then
                            '        Me.CurrentCell = Me.LastCell
                            '        RaiseEvent Respond_On_Row_Edit_Error(Me.LastRowState)
                            '        Exit Sub
                            '    End If
                            'End If
                            'ovaj if se koristi ukoliko imamo greske na nekoj koloni posle setnje levo - desno
                            If Not Me.LastColState Is Nothing Then
                                If Me.LastColState.Row.GetColumnsInError.Length > 0 Then
                                    Me.CurrentCell = Me.LastCell
                                    RaiseEvent Respond_On_Column_Edit_Error(Me.LastColState)
                                    Exit Sub
                                End If
                            End If

                        Case Else

                    End Select
                End If
                'ukoliko smo se uspesno pomerili na sledecu celiju bez editovanja, omogucavamo editovanje grida
                'to je zbog toga sto je readonly = true kad smo u dataview-u u isNew modu.
                If Not tblStl Is Nothing Then
                    tblStl.ReadOnly = False
                End If
            End If

            'pomerili smo se posle promene celije na sledecu, pa cemo za ubuduce pamtiti staru celiju
            Me.LastCell = Me.CurrentCell

        Else
            MsgBox("CurrCellChangedUpdateDataGrid.CurrentCellChanged()" & vbCrLf & "DataSuorce DataGrid-a je tabela dataSet-a, a ne DataView." & vbCrLf & "Moguće greške u predvidjenom ponašanju datagrida.", MsgBoxStyle.Exclamation, "Exception")
        End If

    End Sub


Ovaj grid je zamisljen da se podaci proveravaju dok se korisnik seta po jednom redu,
ali cim skoci u novi red da se update-uje baza. Ukoliko je neka greska 'ne pustam' korisnika van celije. U odgovarajucem momentu podizem update dogadjaj i u formi koja ima taj grid radim sledeci update:
Code:

Private Sub DataGrid1_Update_on_Current_Cell_Changed(ByRef ErrorOnUpdate As Boolean) Handles DataGrid1.Update_on_Current_Cell_Changed
        If DataGrid1.LastRowState.Row.HasErrors Then
            ErrorOnUpdate = True
        Else
            ErrorOnUpdate = False
            Try
                SqlDataAdapter1.Update(ds)
                ErrorOnUpdate = False
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                ErrorOnUpdate = True
            End Try
        End If
    End Sub

Vraca mi se exveption :
Concurrency violation: the UpdateCommand affected 0 records.
ili
could not convert "" to datetime ili tako nesto
Ima li neko resenje?
kopca
 
Odgovor na temu

ilumnis
BG

Član broj: 42070
Poruke: 15
*.sbb.co.yu.

Sajt: www.ilumnis.com


Profil

icon Re: dataset.update problemi14.02.2005. u 14:20 - pre 233 meseci
Vraca mi se exveption :
Concurrency violation: the UpdateCommand affected 0 records.
ili
could not convert "" to datetime ili tako nesto


a to neso bi moglo da znaci mnogo vise od 80 linija koje si okacio ovde.
bar bi neko procitao i dobio ideju.
 
Odgovor na temu

[es] :: .NET :: dataset.update problemi

[ Pregleda: 2332 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.