C# 自datagrid WPF以来更新的bdd
目前,我为我的公司(协会)开发了一个小型计划,该计划允许管理are工人的工作时间、施工现场(工程)的管理(添加、咨询、修改)以及WPF中施工现场(工程)和员工管理的分析(这是我在WPf中的第一个应用程序,到目前为止我一直在WinForms中开发) 申请快结束了,但是我遇到了一个小问题,那就是建筑工地(工程)的改造 我作出一些解释: 我通过数据集在DataGrid中加载(计费)我的表构建站点(工作),其中包含我希望能够修改的列 我的DataGrid的xaml代码:C# 自datagrid WPF以来更新的bdd,c#,wpf,C#,Wpf,目前,我为我的公司(协会)开发了一个小型计划,该计划允许管理are工人的工作时间、施工现场(工程)的管理(添加、咨询、修改)以及WPF中施工现场(工程)和员工管理的分析(这是我在WPf中的第一个应用程序,到目前为止我一直在WinForms中开发) 申请快结束了,但是我遇到了一个小问题,那就是建筑工地(工程)的改造 我作出一些解释: 我通过数据集在DataGrid中加载(计费)我的表构建站点(工作),其中包含我希望能够修改的列 我的DataGrid的xaml代码: <DataGrid x:N
<DataGrid x:Name="dataGrid" HorizontalAlignment="Left" Height="373" Margin="0,47,0,0" VerticalAlignment="Top" Width="774" AutoGenerateColumns="False" ItemsSource="{Binding Path=LoadDataBinding}" CanUserResizeRows="False" TextBlock.TextAlignment="Center" IsReadOnly="False" CellEditEnding="dataGrid_CellEditEnding" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=numero}" Header="Numéro" IsReadOnly="True" TextBlock.TextAlignment="Center"/>
<DataGridTextColumn Binding="{Binding Path=responsable}" Header="Nom du responsable" IsReadOnly="True" TextBlock.TextAlignment="Center"/>
<DataGridTextColumn Binding="{Binding Path=description}" Header="Nom du chantier" IsReadOnly="True" TextBlock.TextAlignment="Center" />
<DataGridTextColumn Binding="{Binding Path=zone}" Header="Zone" IsReadOnly="False" TextBlock.TextAlignment="Center" />
</DataGrid.Columns>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontStyle" Value="Italic"/>
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGrid.ColumnHeaderStyle>
</DataGrid>
因此,我的问题是,现在是如何修改DataGrid的一个单元格,还是修改Bdd中的修改记录
我知道如何用WinForm的DataGridView制作的东西,但是我干了。我参观了论坛,问Google(当我有问题时,我最好的朋友)咨询MSDN,但显然我错过了一些东西
编辑:对于单元格的修改,我使用事件:CellEditEnding
private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
trait.MajDataUtilisateur(ds);
}
public void MajDataUtilisateur(DataSet ds)
{
mbdd.TableMaj(ds);
}
public bool TableMaj(DataSet ds)
{
try
{
combuilder = new MySqlCommandBuilder(da); //création du combuilder et indication du connecteur de données
da.Fill(ds);
da.Update(ds,"LoadDataBinding"); //on envoie le dataset ds vers le connecteur de données
combuilder.Dispose(); //libération des ressources
return true;
}
catch (MySqlException mySqlException)
{
MySqlException ex = mySqlException;
//MessageBox.Show("Erreur suivante " + ex + " ");
System.Windows.MessageBox.Show("Erreur suivante " + ex + " ");
return false;
}
}
如果您决定首先使用实体框架模型,映射您的BD并用几行代码保存用户修改的实体,那么这可能会更容易 在这种情况下,我总是希望在每行中创建一个保存按钮,单击此按钮将执行代码以保存或编辑该行
private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
trait.MajDataUtilisateur(ds);
}
public void MajDataUtilisateur(DataSet ds)
{
mbdd.TableMaj(ds);
}
public bool TableMaj(DataSet ds)
{
try
{
combuilder = new MySqlCommandBuilder(da); //création du combuilder et indication du connecteur de données
da.Fill(ds);
da.Update(ds,"LoadDataBinding"); //on envoie le dataset ds vers le connecteur de données
combuilder.Dispose(); //libération des ressources
return true;
}
catch (MySqlException mySqlException)
{
MySqlException ex = mySqlException;
//MessageBox.Show("Erreur suivante " + ex + " ");
System.Windows.MessageBox.Show("Erreur suivante " + ex + " ");
return false;
}
}