I am new to C # and WPF. Despite the extensive documentation, tutorials, and previous questions I read, I cannot find my script.
What i have
I have a WPF application in C # with a single window containing a ListBox. A ListBox defines a DataTemplate to display its elements with a TextBox for each ListItem.
I have a Microsoft SQL Express Server on the same computer that contains the database with the name of Testthe submission of the name Client, which provides columns id INT PRIMARY KEY IDENTITYand name VARCHAR(50) NOT NULLother table and stored procedure name Client_update(@id, @name)that sets a column nameclient, idwhich @idthrough a simple UPDATE statement in the same table .
What I'm trying to achieve
I am trying to ensure that the ListBox is populated by loading the window and that changes to the data (which are contained in the text fields) are saved in the database (via a stored procedure) by switching the focus to another GUI component.
What I've done
LINQ to SQL Classes Visual Studio, DataContext DataClassesDataContext.
O-R Visual Studio, Client Client_update(id, name). ( GUI OR Designer), Client id, - Client_update(id, name) ( ).
XAML ( MainWindow.xaml.cs):
<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Loaded="Window_Loaded">
<ListBox x:Name="myListBox">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=name Mode=TwoWay}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Window>
TextBox Text name , , TwoWay.
Trigger TextBox OnLostFocus, .
- ( MainWindow.cs):
namespace Test
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DataClassesDataContext dataContext = new DataClassesDataContext();
IEnumerable<Client> clients = from c in dataContext.Client
select c;
myListBox.ItemsSource = clients;
}
}
}
.
System.InvalidOperationException System.Data.Linq.dll, " AutoSync ". .
, O-R AutoSync Always . OnUpdate, , OnInsert Never .
, , , , . ( Microsoft SQL Management Studio )
AutoSync ?
, ? , , ?
PS , , Prettify, - XAML , XML # (cs), , , .
№ 1: , .
. # 2: , , . (.. Client Clients)