rani rani - 23 days ago 5
C# Question

how to bind datagridview with two tables, and perform CURD operation in WPF

Here is My Table SQL Script:

First Table:

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]"


Here is my design:

<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>


I want CRUD operation in this Datagrideview how I implement Please Help..

All operation should perform within this datagridview delete operation perform when we click keyboard delete button . edit and insert operation perform within datagridview column

Answer

You wont be able to bind it to 2 tables at once. You would need to either rethink your database design or you would need to bring the 2 tables in as a single query, possibly using a union.

Comments