如何使用wpf数据绑定插入记录?

发布于 2024-11-03 13:46:01 字数 1486 浏览 4 评论 0原文

我是 WPF 新手,所以请耐心等待,

我创建了一个窗口,用于

在导航和更新工作时

管理“配置文件”记录,但我似乎无法插入工作,这也是

非常简单的代码

Imports System.Collections.ObjectModel

Public Class Window1
Dim WindowEntities As New DataEntities
Dim WindowList As ObservableCollection(Of Profile)

Function ProfilesViewSource() As CollectionViewSource
    Return CType(FindResource("ProfilesViewSource"), CollectionViewSource)
End Function
Function DefaultView() As CollectionView
    Return CollectionViewSource.GetDefaultView(ProfilesViewSource.View)
End Function

Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles MyBase.Loaded
    WindowList = New ObservableCollection(Of Profile)(From x In WindowEntities.Profiles Order By x.ProfileName)
    ProfilesViewSource.Source = WindowList
End Sub

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnSave.Click
    WindowEntities.SaveChanges()
End Sub

Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnAdd.Click
    WindowList.Add(New Profile)
    DefaultView.MoveCurrentToLast()
End Sub

Private Sub btnNext_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnNext.Click
    DefaultView.MoveCurrentToNext()
End Sub
End Class

我按添加时的 ,我得到一个新的空记录,当我填写它时,我看到集合看到了它,因为有一个显示配置文件的onform列表框,并且它被列在那里,所以它实际上附加到列表中,但是savechanges命令确实不将其插入数据库

可能会插入时会出现一些验证错误,但随后我会得到一些指示,对吧?现在它只是默默地失败。就好像我从来没有承诺过改变一样,

非常感谢你们的帮助

im new to wpf, so please bear with me

i made a window for the purpose of managing "profile" records

while the navigation and updating is working

i cannot seem to get insertion working, as well

heres the very simple code

Imports System.Collections.ObjectModel

Public Class Window1
Dim WindowEntities As New DataEntities
Dim WindowList As ObservableCollection(Of Profile)

Function ProfilesViewSource() As CollectionViewSource
    Return CType(FindResource("ProfilesViewSource"), CollectionViewSource)
End Function
Function DefaultView() As CollectionView
    Return CollectionViewSource.GetDefaultView(ProfilesViewSource.View)
End Function

Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles MyBase.Loaded
    WindowList = New ObservableCollection(Of Profile)(From x In WindowEntities.Profiles Order By x.ProfileName)
    ProfilesViewSource.Source = WindowList
End Sub

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnSave.Click
    WindowEntities.SaveChanges()
End Sub

Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnAdd.Click
    WindowList.Add(New Profile)
    DefaultView.MoveCurrentToLast()
End Sub

Private Sub btnNext_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles btnNext.Click
    DefaultView.MoveCurrentToNext()
End Sub
End Class

when i press add, i get a new empty record, when i fill it in, i see that the collection sees it, as there is an onform listbox showing the profiles, and it gets listed there, so its actually attached to the list, but the savechanges command does not insert it into the db

there may be some validation errors upon insert, but then i would get some indication, right? now its just silently failing. as if i never tied to commit changes

thank you very much for your help fellows

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只等公子 2024-11-10 13:46:01

(作者:IVerzin
1. 创建新的配置文件。
2.添加到WindowEntities中
3.添加到WindowList中

(by IVerzin)
1. create new Profile.
2. Add it to WindowEntities
3. Add it to WindowList

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文