I'm bit new to C#. This is my code. When i click edit button in grid, it should be update the database. But now it is not update the database from this code. The database has original value after editing. after click edit button, it is shown a message box "Row Updated Successfully" according to my C# code. No errors showing when run the programme. Please show me the direction to solve this.

Here is code....XAML

<Grid>
        <TextBox Height="23" HorizontalAlignment="Left" Margin="12,21,0,0" Name="txtContNo" VerticalAlignment="Top" Width="120" />
        <Button Content="Load" Height="23" HorizontalAlignment="Left" Margin="157,21,0,0" Name="btnLoad" VerticalAlignment="Top" Width="75" Click="btnLoad_Click" />
        <DataGrid AutoGenerateColumns="False" Height="374" HorizontalAlignment="Left" Margin="12,61,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="666" AllowDrop="True" UseLayoutRounding="True" BorderThickness="3" AlternationCount="2" SelectionMode="Single" IsEnabled="True" IsSynchronizedWithCurrentItem="True" SelectionUnit="FullRow" IsReadOnly="False" IsManipulationEnabled="True">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Path=Date1, Mode=OneTime}"   Width="70" Header="DATE" FontStyle="Normal" FontWeight="Normal" />
                <DataGridTextColumn Binding="{Binding Path=Temp00, Mode=OneTime}"  Width="SizeToHeader" Header="TEMP0000" />
                <DataGridTextColumn Binding="{Binding Path=Temp06, Mode=OneTime}"  Width="SizeToHeader" Header="TEMP0600" />
                <DataGridTextColumn Binding="{Binding Path=Temp12, Mode=OneTime}"  Width="SizeToHeader" Header="TEMP1200" />
                <DataGridTextColumn Binding="{Binding Path=Temp18, Mode=OneTime}"  Width="SizeToHeader" Header="TEMP1800" />
                <DataGridTextColumn Binding="{Binding Path=DLane, Mode=OneTime}"  Width="50" Header="LANE" />
                <DataGridTextColumn Binding="{Binding Path=DVentilation, Mode=OneTime}"  Width="SizeToHeader" Header="VENTILATION" />
                <DataGridTextColumn Binding="{Binding Path=DRemarks, Mode=OneTime}"  Width="SizeToHeader" Header="REMARKS" />
                <DataGridTemplateColumn Header="Edit Row">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Edit" Click="EditButton_Click" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Delete Row">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Delete" Click="DeleteButton_Click" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
            <DataGrid.AlternatingRowBackground>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#7FFF00FF" Offset="0" />
                    <GradientStop Color="White" Offset="1" />
                </LinearGradientBrush>
            </DataGrid.AlternatingRowBackground>
        </DataGrid>
        <Label Content="Container Number" Height="28" HorizontalAlignment="Left" Margin="9,0,0,0" Name="label1" VerticalAlignment="Top" />
    </Grid>

Code...C#

namespace comoco_wpf
{
    /// <summary>
    /// Interaction logic for WindowEdit1.xaml
    /// </summary>
    public partial class WindowEdit1 : Window
    {


        public WindowEdit1()
        {
            InitializeComponent();

        }



        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            LoadDates();
        }


        private void LoadDates()
        {
            comocoLTSDataContext dc = new comocoLTSDataContext();
            var history = from d in dc.DCdates
                          where d.DCcontainer.ContainerNo == txtContNo.Text
                          select d;
            dataGrid1.ItemsSource = history;
        }


        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            comocoLTSDataContext dc = new comocoLTSDataContext();
            DCdate dateRow = dataGrid1.SelectedItem as DCdate;
            DCdate date = (from d in dc.DCdates
                           where d.GKId == dateRow.GKId & d.DId == dateRow.DId
                           select d).Single();
            dc.DCdates.DeleteOnSubmit(date);
            dc.SubmitChanges();
            MessageBox.Show("Row deleted successfully");
            LoadDates();
        }

        private void EditButton_Click(object sender, RoutedEventArgs e)
        {

            try
            {
                comocoLTSDataContext dc = new comocoLTSDataContext();
                DCdate dateRow = dataGrid1.SelectedValue as DCdate;
                //int m = dateRow.GKId;
                var date = (from d in dc.DCdates
                            where d.DId == dateRow.DId & d.DCcontainer.ContainerNo == txtContNo.Text
                            select d).Single();
                date.Date1 = dateRow.Date1;
                date.Temp00 = dateRow.Temp00;
                date.Temp06 = dateRow.Temp06;
                date.Temp12 = dateRow.Temp12;
                date.Temp18 = dateRow.Temp18;
                date.DLane = dateRow.DLane;
                date.DVentilation = dateRow.DVentilation;
                date.DRemarks = dateRow.DRemarks;
                dc.SubmitChanges();
                MessageBox.Show("Row Updated Successfully");
                LoadDates();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            } 

        }

        }   
    }

What database is this going against?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.