2016-11-10 48 views
0

執行CRUD操作這裏是我的表結構:如何綁定的DataGridView兩個表,並在WPF

第一個表:

CREATE TABLE [dbo].[tblToolModification_Pramary] 
(
    [id] [int] IDENTITY(1,1) NOT NULL, 
    [ReportNo] [varchar](50) NOT NULL, 
    [ToolModificationDate] [varchar](50) NULL, 
    [ProductCode] [varchar](50) NULL, 
    [ProductionDescription] [varchar](50) NULL, 
    [DrawingNo] [varchar](50) NULL, 
    [DIENo] [varchar](50) NULL, 
    [NoOfCavity] [varchar](50) NULL, 
    [DIEMakerCode] [varchar](50) NULL, 
    [DIEMakerName] [varchar](50) NULL, 

    CONSTRAINT [PK_tblToolModification_Pramary] 
     PRIMARY KEY CLUSTERED ([ReportNo] ASC) 
        WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
          IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 

CREATE TABLE [dbo].[tblToolModification_Foreign] 
(
    [id] [int] IDENTITY(1,1) NOT NULL, 
    [ReportNo] [varchar](50) NOT NULL, 
    [SrlNo] [varchar](50) NULL, 
    [DrawingDimension] [varchar](50) NULL, 
    [RequiredDimension] [varchar](50) NULL, 
    [ActualInDie] [varchar](50) NULL, 
    [ActionInNeeded] [varchar](50) NULL, 
    [ResultModification] [varchar](50) NULL, 

    CONSTRAINT [PK_tblToolModification_Foriegn] 
     PRIMARY KEY CLUSTERED ([id] ASC) 
        WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
          IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 

這裏是我的設計:

<Window x:Class="demo.Foundry.Sample.Tool_Modification_View" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell" 
     xmlns:col="clr-namespace:System.Collections;assembly=mscorlib" 
     Icon="/img\F_Logo.png" 
     WindowStyle="None" 
     ShowInTaskbar="False" 
     Title="Tool Modification View" 
     ResizeMode="NoResize" 
     Height="692" 
     Width="1591.9" 
     Background="#d9f9f7" 
     Loaded="Window_Loaded"> 
    <Grid Margin="0,0,0,-45"> 
     <Label Content="Tool Modification View" 
       VerticalAlignment="Top" 
       Height="25" 
       HorizontalContentAlignment="Center" 
       Background="{DynamicResource {x:Static SystemColors.ActiveCaptionBrushKey}}" /> 
     <Grid Margin="10,30,4,29"> 
      <Rectangle HorizontalAlignment="Left" 
         Fill="DarkGreen" 
         Height="50" 
         Margin="61,0,0,0" 
         Stroke="Black" 
         VerticalAlignment="Top" 
         Width="1163" /> 
      <Label Content="Tool Modification View" 
        Foreground="White" 
        FontWeight="Bold" 
        HorizontalAlignment="Left" 
        Margin="575,11,0,0" 
        VerticalAlignment="Top" 
        Width="155" 
        RenderTransformOrigin="0.03,0.423" 
        Height="27" /> 
      <DataGrid Name="dgDIE_Outward_DC" 
         HorizontalAlignment="Left" 
         Margin="61,50,0,0" 
         VerticalAlignment="Top" 
         ItemsSource="{Binding}" 
         AutoGenerateColumns="False" 
         Width="1163" 
         Height="310" 
         AlternatingRowBackground="{DynamicResource {x:Static SystemColors.ActiveCaptionBrushKey}}"> 
       <DataGrid.Columns> 
        <DataGridTextColumn Binding="{Binding ReportNo, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="80" 
             Header="Report No" 
             IsReadOnly="True" /> 
        <DataGridTextColumn Binding="{Binding ToolModificationDate, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="80" 
             Header="Date" /> 
        <DataGridTextColumn Binding="{Binding SrlNo, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="50" 
             Header="Sr.No" /> 
        <DataGridTextColumn Binding="{Binding ProductCode, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="80" 
             Header="Product" /> 
        <DataGridTextColumn Binding="{Binding ProductionDescription, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="150" 
             Header="Description" /> 
        <DataGridTextColumn Binding="{Binding DrawingNo, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="100" 
             Header="Drawing" /> 
        <DataGridTextColumn Binding="{Binding DIENo, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="55" 
             Header="DIE No." /> 
        <DataGridTextColumn Binding="{Binding NoOfCavity, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="55" 
             Header="Cavity" /> 
        <DataGridTextColumn Binding="{Binding DIEMakerName, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="100" 
             Header="Vendor Name" /> 
        <DataGridTextColumn Binding="{Binding DrawingDimension, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="150" 
             Header="Drawing Dimension" /> 
        <DataGridTextColumn Binding="{Binding RequiredDimension, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="150" 
             Header="Required Dimension" /> 
        <DataGridTextColumn Binding="{Binding ActualInDie, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="150" 
             Header="Actual In DIE" /> 
        <DataGridTextColumn Binding="{Binding ActionInNeeded, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="150" 
             Header="Action Needed" /> 
        <DataGridTextColumn Binding="{Binding ResultModification, NotifyOnSourceUpdated=True, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
             Width="200" 
             Header="Result After Modification" /> 
       </DataGrid.Columns> 
      </DataGrid> 
      <Rectangle HorizontalAlignment="Left" 
         Fill="Beige" 
         Height="50" 
         Margin="62,356,0,0" 
         Stroke="Black" 
         VerticalAlignment="Top" 
         Width="1163" /> 
      <Label Content="Report No." 
        HorizontalAlignment="Left" 
        Margin="62,365,0,0" 
        VerticalAlignment="Top" 
        RenderTransformOrigin="1.639,0.468" 
        Width="65" /> 
      <ComboBox TabIndex="6" 
         HorizontalAlignment="Left" 
         Margin="127,365,0,0" 
         VerticalAlignment="Top" 
         Width="150" 
         Height="28" 
         RenderTransformOrigin="0.474,1.094" /> 
      <Label Content="Product" 
        HorizontalAlignment="Left" 
        Margin="277,365,0,0" 
        VerticalAlignment="Top" 
        RenderTransformOrigin="1.639,0.468" 
        Width="65" /> 
      <ComboBox TabIndex="6" 
         HorizontalAlignment="Left" 
         Margin="331,365,0,0" 
         VerticalAlignment="Top" 
         Width="150" 
         Height="28" 
         RenderTransformOrigin="0.474,1.094" /> 
      <Label Content="Drawing" 
        HorizontalAlignment="Left" 
        Margin="495,365,0,0" 
        VerticalAlignment="Top" 
        RenderTransformOrigin="1.639,0.468" 
        Width="65" /> 
      <ComboBox TabIndex="6" 
         HorizontalAlignment="Left" 
         Margin="550,366,0,0" 
         VerticalAlignment="Top" 
         Width="150" 
         Height="28" 
         RenderTransformOrigin="0.474,1.094" /> 
      <Button Name="btnExit" 
        Content="Exit" 
        HorizontalAlignment="Left" 
        Margin="843,360,0,0" 
        VerticalAlignment="Top" 
        Width="231" 
        Click="btnExit_Click" /> 
     </Grid> 
    </Grid> 
</Window> 

我想要在這個DataGridView CRUD操作 - 我該如何實現?請幫忙..

所有的操作應該在這個datagridview中執行刪除操作,當我們點擊鍵盤刪除按鈕時執行。在datagridview列中編輯和插入操作執行

+0

現在我不能綁定datagridview兩個表 – rani

+0

我沒有任何想法它將如何執行 – rani

+0

你不能一次綁定到2個表。您需要重新考慮您的數據庫設計,否則您需要將這兩個表作爲單個查詢,可能使用聯合。 – ThatChris

回答

0

您無法一次將它綁定到2個表。您需要重新考慮您的數據庫設計,否則您需要將這兩個表作爲單個查詢,可能使用聯合。