I have made a database using model-first approach.
I have three tables:
Books
with properties BookID, Title.
Authors
with properties AuthorID, Name, Surname.
AuthorBook
table in order to orginise many-to-many connection with properties AuthorBookID, AuthorID, BookID.
All these tables have some data.
I have a textbox where I want to type a title of a book or a name or a surname of author of this book and the selected (by stored procedure) items will be shown in DataGrid.
I've made a stored procedure which succesfully does this function in SQL Management Studio and in script in Visual Studio. But I don't know how to make it work by code and how to use it correctly.
Xaml:
<Canvas>
<TextBox x:Name="SearchBox" Width="193" Height="32" Canvas.Left="38" Canvas.Top="38"></TextBox>
<Button Name="SearchButton" Click="SearchButton_OnClick" Content="Search" Canvas.Left="204" Canvas.Top="80" Height="30" Width="64"></Button>
<DataGrid x:Name="Info" ItemsSource="{Binding Path=Authorslist1}" Background="Honeydew" Canvas.Top="200" Canvas.Left="30" Width="259" Height="50" ></DataGrid>
</Canvas>
C#:
public partial class UserPage : Window
{
Model1Container db1 = new Model1Container();
private MainWindow mv = new MainWindow();
public UserPage(Model1Container d, MainWindow m)
{
InitializeComponent();
DataContext = this;
db1 = d;
mv = m;
}
private void SearchButton_OnClick(object sender, RoutedEventArgs e)
{
}
Script:
CREATE PROCEDURE [dbo].AuthorProcedure1
@name nvarchar(50)
AS
SELECT
BookSet.Title, AuthorSet.Name, AuthorSet.Surname
FROM [dbo].AuthorBookSet
JOIN BookSet ON BookSet.BookID=AuthorBookSet.BookID
JOIN AuthorSet ON AuthorSet.AuthorID=AuthorBookSet.AuthorID
WHERE Title=@name
GO