Principales respuestas
No guarda valores dataset

Pregunta
-
Hola,
hice un codigo a partir de un ejemplo simple y parece que todo va bien... pero no me guarda los cambios/entradas en el Dataset.
lo tengo declarado:
Public Class Window1 Private amistatsData As New DataSet1 Private taamistat As New DataSet1TableAdapters.amistatsTableAdapter Private taManager As New DataSet1TableAdapters.TableAdapterManager Private View As CollectionView ' public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) Public Property CalcularEdad() As Integer Get Return 1 End Get Set(ByVal value As Integer) End Set End Property Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded Me.taamistat.Fill(Me.amistatsData.amistats) Me.taManager.amistatsTableAdapter = taamistat Me.DataContext = Me.amistatsData.amistats Me.View = CollectionViewSource.GetDefaultView(Me.amistatsData.amistats) End Sub Private Sub btdarrer_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btdarrer.Click Me.View.MoveCurrentToFirst() 'anem a la primera posició End Sub Private Sub bt_enrera_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles bt_enrera.Click If Me.View.CurrentPosition > 0 Then Me.View.MoveCurrentToPrevious() 'anem a la anterior End If End Sub Private Sub Bt_endavant_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Bt_endavant.Click If Me.View.CurrentPosition < Me.View.Count - 1 Then Me.View.MoveCurrentToNext() 'anem al seguent End If End Sub Private Sub Bt_darrer_recent_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Bt_darrer_recent.Click Me.View.MoveCurrentToLast() End Sub Private Sub Bt_elimina_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Bt_elimina.Click If Me.View.CurrentPosition > -1 Then Dim row = CType(Me.View.CurrentItem, System.Data.DataRowView).Row row.Delete() End If End Sub Private Sub Bt_desfes_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Bt_desfes.Click If Me.amistatsData.HasChanges Then If MessageBox.Show("Esteu segurs de fer aquests canvis?", Me.Title, MessageBoxButton.YesNo) = MessageBoxResult.Yes Then Me.amistatsData.RejectChanges() End If End If End Sub Private Sub Bt_desa_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Bt_desa.Click Try ' Me.taamistat.Update(amistatsData.amistats) 'Me.amistatsData.AcceptChanges() If Me.amistatsData.HasChanges Then If Me.taManager.UpdateAll(Me.amistatsData) > 0 Then MsgBox("Guardat") End If End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Private Sub Bt_nou_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Bt_nou.Click Dim row = Me.amistatsData.amistats.NewamistatsRow row.nom = "[ nom ]" row.cognom = "[ cognom ]" row.altres_dades = "entreu si hi ha alguna cosa a remarcar" Me.amistatsData.amistats.AddamistatsRow(row) Me.View.MoveCurrentToLast() End Sub End Class
y en la ventana tengo los bindings creo que correctos ya que me permite visualizar todos los campos...el caso es que si le doy al Bt_desa_Click me lanza el msgbox de confirmacion y si me muevo por los registros me salen los cambios, pero como que no me llegan al DATASET (lo miro y no estan los cambios) al salir y volver a cargar el formulario no tengo los cambios..
como lo puedo solucionar?
Gracias
<br/>
Respuestas
-
Ya esta solucionado...
he encontrado/descargado la herramienta de pasar de accessa SQL server la migration assistant i ahora des de SQL server no hay ningun problema.... no se porque con access no me lo guardava.. alguien save porqué?
- Marcado como respuesta Spandau lunes, 14 de junio de 2010 8:39
Todas las respuestas
-
Hola
En tu xaml, en el binding de los controles especifica Mode=TwoWay para que los cambios se refresquen en la fuente.
Espero que te funcione, un gran saludo!
MCTS .NET Framework 3.5 Windows Forms Application Development
MCTS .NET Framework 3.5 Windows Presentation Foundation
Visita mi Blog
Sigueme en Twitter -
Hola Josue,
el otro dia ya lo puse en two way y me falla todavia...
actualmente me guarda los cambios que al parar la ejecucion/arrancar...me conserva los valores... pero al salir de vb i volver a entrar al no cargarme los cambios en Dataset/BD... los pierdo
Gracias.
<Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title=" AGENDA " x:Name="Window1" Height="434" Width="662"> <!--he hagut d'afegir el xname perque el property calcula edat em surti--> <Grid Width="570"> <Button Content="|<" Height="30" HorizontalAlignment="Left" Margin="5,8,0,0" Name="btdarrer" VerticalAlignment="Top" Width="40" /> <Button Content="<" Height="30" HorizontalAlignment="Left" Margin="51,8,0,0" Name="bt_enrera" VerticalAlignment="Top" Width="40" /> <Button Content=">" Height="30" HorizontalAlignment="Left" Margin="97,8,0,0" Name="Bt_endavant" VerticalAlignment="Top" Width="40" /> <Button Content=">|" Height="30" HorizontalAlignment="Left" Margin="143,8,0,0" Name="Bt_darrer_recent" VerticalAlignment="Top" Width="40" /> <Button Content="nou" Height="30" HorizontalAlignment="Left" Margin="189,8,0,0" Name="Bt_nou" VerticalAlignment="Top" Width="40" /> <ComboBox Height="32" HorizontalAlignment="Left" Margin="235,8,0,0" Name="Cbox_cerca" VerticalAlignment="Top" Width="162" > </ComboBox> <Button Content="desa" Height="32" HorizontalAlignment="Left" Margin="403,8,0,0" Name="Bt_desa" VerticalAlignment="Top" Width="49" /> <Button Content="elimina" Height="32" HorizontalAlignment="Left" Margin="513,8,0,0" Name="Bt_elimina" VerticalAlignment="Top" Width="49" /> <StackPanel Height="342" HorizontalAlignment="Left" Margin="0,47,0,0" Name="StackPanel1" VerticalAlignment="Top" Width="222"> <Label Content="ID" Height="34" Name="LB_id" Width="219" FlowDirection="RightToLeft" /> <Label Content="distintiu" FlowDirection="RightToLeft" Height="34" Name="lb_dis" Width="219" /> <Label Content="NOM" FlowDirection="RightToLeft" Height="34" Name="lb_nom" Width="219" /> <Label Content="Cognoms" FlowDirection="RightToLeft" Height="34" Name="lb_cognoms" Width="219" /> <Label Content="data naixement" FlowDirection="RightToLeft" Height="34" Name="lb_data_naix" Width="219" /> <Label Content="dades electròniques" FlowDirection="RightToLeft" Height="34" Name="lb_dadeselectroniques" Width="219" /> <Label Content="telèfon mòbil" FlowDirection="RightToLeft" Height="34" Name="lb_telefon_mobil" Width="219" /> <Label Content="telèfon fix" FlowDirection="RightToLeft" Height="34" Name="lb_fixe" Width="219" /> <Label Content="altres" FlowDirection="RightToLeft" Height="34" Name="altres" Width="219" /> </StackPanel> <StackPanel Height="343" HorizontalAlignment="Left" Margin="227,47,0,0" Name="StackPanel2" VerticalAlignment="Top" Width="335"> <Grid Height="64"> <Grid.ColumnDefinitions> <!-- Definición de 3 Columas --> <ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <!-- Definición de 2 Filas--> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <TextBox Height="30" Name="tx_id" Grid.Column="0" Grid.Row="0" Width="auto" IsReadOnly="True" Text="{Binding Path=id, Mode=OneWay}" HorizontalAlignment="Left" /> <Label Content=" edat: " Grid.Column="1" Grid.Row="0" Height="34" Name="lb_edad" Width="59" HorizontalAlignment="Left" /> <TextBox Height="30" Name="tx_edad" Width="50" Grid.Column="1" Grid.Row="0" IsReadOnly="True" Text="{Binding CalcularEdad, ElementName=Window1}" HorizontalAlignment="Right" /> </Grid> <TextBox Height="34" Name="tb_distintiu" Width="auto" Text="{Binding Path=distintiu, Mode=TwoWay}" FontFamily="Cambria" FontSize="16"/> <TextBox Height="36" Name="tx_nom" Width="auto" Text="{Binding Path=nom, Mode=TwoWay}" FontFamily="Cambria" FontSize="16" /> <TextBox Height="36" Name="tx_cognom" Width="auto" Text="{Binding Path=cognom, Mode=TwoWay}" FontFamily="Cambria" FontSize="16" /> <TextBox Height="36" Name="tx_data_naixement" Width="auto" Text="{Binding Path=data_naixement, Mode=TwoWay}" FontFamily="Cambria" FontSize="16" /> <TextBox Height="31" Name="tx_correu" Width="auto" Text="{Binding Path=dades_electroniques, Mode=TwoWay}" FontFamily="Cambria" FontSize="16"/> <TextBox Height="32" Name="tx_mòbil" Width="auto" Text="{Binding Path=telefons, Mode=TwoWay}" FontFamily="Cambria" FontSize="16" /> <TextBox Height="32" Name="tx_fix" Width="auto" Text="{Binding Path=mobil, Mode=TwoWay}" FontFamily="Cambria" FontSize="16" /> <TextBox Height="79" Name="Tx_altres" Width="auto" Text="{Binding Path=altres_dades, Mode=TwoWay}" FontFamily="Cambria" FontSize="16" /> </StackPanel> <Button Content="desfés" Height="32" HorizontalAlignment="Left" Margin="458,7,0,0" Name="Bt_desfes" VerticalAlignment="Top" Width="49" /> </Grid> </Window>
-
Ya esta solucionado...
he encontrado/descargado la herramienta de pasar de accessa SQL server la migration assistant i ahora des de SQL server no hay ningun problema.... no se porque con access no me lo guardava.. alguien save porqué?
- Marcado como respuesta Spandau lunes, 14 de junio de 2010 8:39