本文介绍了DataRow - 如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嘿小组, 我想知道是否有人能帮助我?我遇到麻烦 使用DataViews和DataRows :( 我只是不明白,所以我想知道是否有人会如此善良 修改下面的代码以包含Datarows和Dataviews,也许还可以解释 a还有什么? 非常感谢 问候 MCN Private Sub frmMainMenuPasswords_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)处理MyBase .Load cmDsPasswordList = BindingContext(dsPasswordList," PasswordList") mlLoading = True ''开始填充数据集 尝试 dsPasswordList.EnforceConstraints = False dsArcirisUsers.EnforceConstraints = False 尝试 Me.odcPasswordLists.Open() '填写密码列表数据集 Me.odaDepartments.Fill(dsPasswordList) Me.odaPasswordList.Fill(dsPasswordList) Catch fillException As System.Exception 抛出fillException 最后 ''如果数据集绑定失败则启用 - 启用将 导致BIG数据集 ''dsPasswordList.EnforceConstraints = True Me.odcPasswordLists.Close() 结束尝试 Catch eLoad As System.Exception System.Windows.Forms.MessageBox.Show(eLoad.Message) 最后 mlLoading = False 结束尝试 ''填充数据集结束 结束子 ''开始更改位置代码 - 密码列表 Private Sub cmDsPasswordList_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs)处理cmDsPasswordList.PositionChanged DsPasswordList_PositionChanged() End Sub Pri vate Sub cboPasswordListsDepartment_SelectedIndexChanged(由Val发送者 As Object,ByVal e As System.EventArgs)句柄 cboPasswordListsDepartment.SelectedIndexChanged Me.BindingContext(dsPasswordList ,密码列表。)。EndCurrentEdit() 如果是Me.BindingContext(dsPasswordList," PasswordList")。Position<> -1 而不是mlLoading然后 dsPasswordList.PasswordList.Rows(Me.BindingContext(dsPasswordList, " PasswordList" ).Position).Item(" DepartmentID")= Me.cboPasswordListsDepartment.SelectedValue 结束如果 结束子 Private Sub DsPasswordList_PositionChanged() Me.BindingContext(dsPasswordList," PasswordList")。EndCurrentEdit() 如果是Me.BindingContext(dsPasswordList) ,密码列表)。位置<> -1 而不是mlLoading然后 Me.cboPasswordListsDepartment.SelectedValue = dsPasswordList.PasswordList.Rows(Me.BindingContext(dsPasswordList, " PasswordList")。Position).Item(" DepartmentID") 结束如果 结束子 ''结束位置更改代码 - 密码列表 ''PasswordLists代码开始 Private Sub btnPasswordListsDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)处理btnPasswordListsDelete.Click 如果MessageBox.Show(你确定要删除吗?, " ;警告!!!!",MessageBoxButtons.OKCancel)= DialogResult.OK然后 If(Me.BindingContext(dsPasswordList," PasswordList")。Count> 0) 然后 Me.BindingContext(dsPasswordList, " PasswordList")。RemoveAt(Me.BindingContext(dsPassw ordList, " ; PasswordList"。)POSITI on) 结束如果 结束如果 结束子 私人子btnPasswordListsAdd_Click(ByVal发件人)作为System.Object, ByVal e As System.EventArgs)处理btnPasswordListsAdd.Click ''重置组合框 - 由于M $ Bug选择索引两次 cboPasswordListsDepartment.Text ="" cboPasswordListsDepartment.SelectedIndex = -1 cboPasswordListsDepartment.SelectedIndex = -1 尝试 Me.BindingContext(dsPasswordList, " PasswordList")。EndCurrentEdit() Me.BindingContext(dsPasswordList," PasswordList" ).AddNew() Catch eEndEdit As System.Exception System.Windows.Forms.MessageBox.Show(eEndEdit.Mess age) 结束尝试 End Sub Private Sub btnPasswordListsCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)处理btnPasswordListsCancel.Click Me.BindingCont ext(dsPasswordList, " PasswordList")。CancelCurrentEdit() End Sub Private Sub btnPasswordListsUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)处理btnPasswordListsUpdate.Click 如果MessageBox.Show(你确定要保存更改吗?, "警告!!!!",MessageBoxButtons.OKCancel)= DialogResult.OK然后 尝试 Dim objDataSetChanges As Excellence.NET .dsPasswordList = New Excellence.NET.dsPasswordList() Me.BindingContext(dsPasswordList, " PasswordList")。EndCurrentEdit() objDataSetChanges = CType(dsPasswordList.GetChanges, Excellence.NET.dsPasswordList) If(Not(objDataSetChanges)Is Nothing)然后 尝试 如果(不(dsPasswordList)什么都没有)那么 Me.odcPasswordLists.Open() odaDepartments。更新(dsPasswordList) odaPasswor dList.Update(dsPasswordList) 结束如果 Catch updateException As System.Exception 抛出updateException 最后 Me.odcPasswordLists.Close() 结束尝试 结束如果 dsPasswordList.Merge(objDataSetChanges) dsPasswordList.AcceptChanges() Catch eUpdate As System.Exception System.Windows.Forms.MessageBox.Show(eUpdate.Messa ge) 结束尝试 结束如果 结束子 解决方案 Private Sub frmMainMenuPasswords_Load(ByVal sender As System.Object,ByVal $ b $ as As System。处理MyBase.Load cmDsPasswordList = BindingContext(dsPasswordList," PasswordList") mlLoading = True ''开始填充数据集尝试 dsPasswordList.EnforceConstraints = False dsArcirisUsers.EnforceConstraints = False 尝试 Me.odcPasswordLists.Open()''填写密码列表数据集 Me.odaDepartments.Fill(dsPasswordList) Me.odaPasswordList.Fill(dsPasswordList) Catch fillException As System.Exception 抛出fillException 最后''要启用如果数据集绑定失败 - 启用将导致大数据集''dsPasswordList.EnforceConstraints = True Me.odcPasswordLists.Close()结束尝试捕获eLoad作为系统.Exception System.Windows.Forms.MessageBox.Show(eLoad.Message)最后 mlLoading = False 结束尝试''填充数据集结束结束子 ''开始更改位置代码 - 密码列表私有子cmDsPasswordList_PositionChanged(ByVal发送者为对象, ByVal e As System.EventArgs)处理cmDsPasswordList.PositionChanged DsPassword List_PositionChanged() End Sub 私人子cboPasswordListsDepartment_SelectedIndexChanged(由Val 发件人作为对象,ByVal e As System.EventArgs)处理 cboPasswordListsDepartment.SelectedIndexChanged Me.BindingContext(dsPasswordList," PasswordList")。EndCurrentEdit()如果是Me.BindingContext(dsPasswordList," PasswordList")。Position <> -1而不是mlLoading然后 dsPasswordList.PasswordList.Rows(Me.BindingContext(dsPasswordList," PasswordList))。Position).Item(" DepartmentID")= Me.cboPasswordListsDepartment.SelectedValue 结束如果结束Sub 私有子DsPasswordList_PositionChanged() Me.BindingContext(dsPasswordList," PasswordList")。EndCurrentEdit() 如果Me.BindingContext(dsPasswordList," PasswordList")。Position <> -1而不是mlLoading然后 Me.cboPasswordListsDepartment.SelectedValue = dsPasswordList.PasswordList.Rows(Me.BindingContext(dsPasswordList," PasswordList))。Position).Item(" DepartmentID" ;)结束如果结束子''结束位置更改代码 - 密码列表 ''密码列表代码开始私有子btnPasswordListsDelete_Click(ByVal sender as System.Object,ByVal e As System.EventArgs)处理btnPasswordListsDelete.Click 如果MessageBox.Show(你确定要删除吗?,"警告!!!!",MessageBoxButtons.OKCancel)= DialogResult.OK然后 If(Me.BindingContext(dsPasswordList," PasswordList")。Count> 0)然后我。 BindingContext(dsPasswordList," PasswordList")。RemoveAt(Me.BindingContext(dsPassw ordList," PasswordList"。)。Position)结束如果结束如果 私有子btnPasswordListsAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)处理btnPasswordListsAdd.Click ''重置组合框 - 选择索引两次由于M Hey Group,I wondered if somebody would be so kind as to help me? Im having troublewith DataViews and DataRows:(I just don`t understand, so I wondered if somebody would be so kind enoughtto modify my code below to include Datarows and Dataviews and maybe explaina little aswell?Many ThanksRegardsMCNPrivate Sub frmMainMenuPasswords_Load(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles MyBase.LoadcmDsPasswordList = BindingContext(dsPasswordList, "PasswordList")mlLoading = True''Start of Fill DatasetsTrydsPasswordList.EnforceConstraints = FalsedsArcirisUsers.EnforceConstraints = FalseTryMe.odcPasswordLists.Open()''Fill Password Lists DatasetsMe.odaDepartments.Fill(dsPasswordList)Me.odaPasswordList.Fill(dsPasswordList)Catch fillException As System.ExceptionThrow fillExceptionFinally''To be enabled if Dataset Bindings Fail - Enabling willcause BIG Datasets''dsPasswordList.EnforceConstraints = TrueMe.odcPasswordLists.Close()End TryCatch eLoad As System.ExceptionSystem.Windows.Forms.MessageBox.Show(eLoad.Message )FinallymlLoading = FalseEnd Try''End of Fill DatasetsEnd Sub''Start of Position Changed Code - Password ListsPrivate Sub cmDsPasswordList_PositionChanged(ByVal sender As Object,ByVal e As System.EventArgs) Handles cmDsPasswordList.PositionChangedDsPasswordList_PositionChanged()End SubPrivate Sub cboPasswordListsDepartment_SelectedIndexChanged(By Val senderAs Object, ByVal e As System.EventArgs) HandlescboPasswordListsDepartment.SelectedIndexChangedMe.BindingContext(dsPasswordList, "PasswordList").EndCurrentEdit()If Me.BindingContext(dsPasswordList, "PasswordList").Position <> -1And Not mlLoading ThendsPasswordList.PasswordList.Rows(Me.BindingContext (dsPasswordList,"PasswordList").Position).Item("DepartmentID") =Me.cboPasswordListsDepartment.SelectedValueEnd IfEnd SubPrivate Sub DsPasswordList_PositionChanged()Me.BindingContext(dsPasswordList, "PasswordList").EndCurrentEdit()If Me.BindingContext(dsPasswordList, "PasswordList").Position <> -1And Not mlLoading ThenMe.cboPasswordListsDepartment.SelectedValue =dsPasswordList.PasswordList.Rows(Me.BindingContext (dsPasswordList,"PasswordList").Position).Item("DepartmentID")End IfEnd Sub''End of Position Changed Code - Password Lists''PasswordLists Code StartPrivate Sub btnPasswordListsDelete_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnPasswordListsDelete.ClickIf MessageBox.Show("Are Your Sure You Want To Delete?","WARNING!!!!", MessageBoxButtons.OKCancel) = DialogResult.OK ThenIf (Me.BindingContext(dsPasswordList, "PasswordList").Count > 0)ThenMe.BindingContext(dsPasswordList,"PasswordList").RemoveAt(Me.BindingContext(dsPassw ordList,"PasswordList").Position)End IfEnd IfEnd SubPrivate Sub btnPasswordListsAdd_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnPasswordListsAdd.Click''Reset Combo Box`s - Select Index Twice due to M$ BugcboPasswordListsDepartment.Text = ""cboPasswordListsDepartment.SelectedIndex = -1cboPasswordListsDepartment.SelectedIndex = -1TryMe.BindingContext(dsPasswordList,"PasswordList").EndCurrentEdit()Me.BindingContext(dsPasswordList, "PasswordList").AddNew()Catch eEndEdit As System.ExceptionSystem.Windows.Forms.MessageBox.Show(eEndEdit.Mess age)End TryEnd SubPrivate Sub btnPasswordListsCancel_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnPasswordListsCancel.ClickMe.BindingContext(dsPasswordList,"PasswordList").CancelCurrentEdit()End SubPrivate Sub btnPasswordListsUpdate_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnPasswordListsUpdate.ClickIf MessageBox.Show("Are Your Sure You Want To Save Changes?","WARNING!!!!", MessageBoxButtons.OKCancel) = DialogResult.OK ThenTryDim objDataSetChanges As Excellence.NET.dsPasswordList = NewExcellence.NET.dsPasswordList()Me.BindingContext(dsPasswordList,"PasswordList").EndCurrentEdit()objDataSetChanges = CType(dsPasswordList.GetChanges,Excellence.NET.dsPasswordList)If (Not (objDataSetChanges) Is Nothing) ThenTryIf (Not (dsPasswordList) Is Nothing) ThenMe.odcPasswordLists.Open()odaDepartments.Update(dsPasswordList)odaPasswordList.Update(dsPasswordList)End IfCatch updateException As System.ExceptionThrow updateExceptionFinallyMe.odcPasswordLists.Close()End TryEnd IfdsPasswordList.Merge(objDataSetChanges)dsPasswordList.AcceptChanges()Catch eUpdate As System.ExceptionSystem.Windows.Forms.MessageBox.Show(eUpdate.Messa ge)End TryEnd IfEnd Sub 解决方案 Private Sub frmMainMenuPasswords_Load(ByVal sender As System.Object, ByVale As System.EventArgs) Handles MyBase.Load cmDsPasswordList = BindingContext(dsPasswordList, "PasswordList") mlLoading = True ''Start of Fill Datasets Try dsPasswordList.EnforceConstraints = False dsArcirisUsers.EnforceConstraints = False Try Me.odcPasswordLists.Open() ''Fill Password Lists Datasets Me.odaDepartments.Fill(dsPasswordList) Me.odaPasswordList.Fill(dsPasswordList) Catch fillException As System.Exception Throw fillException Finally ''To be enabled if Dataset Bindings Fail - Enabling will cause BIG Datasets ''dsPasswordList.EnforceConstraints = True Me.odcPasswordLists.Close() End Try Catch eLoad As System.Exception System.Windows.Forms.MessageBox.Show(eLoad.Message ) Finally mlLoading = False End Try ''End of Fill Datasets End Sub ''Start of Position Changed Code - Password Lists Private Sub cmDsPasswordList_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmDsPasswordList.PositionChanged DsPasswordList_PositionChanged() End Sub Private Sub cboPasswordListsDepartment_SelectedIndexChanged(By Valsender As Object, ByVal e As System.EventArgs) Handles cboPasswordListsDepartment.SelectedIndexChanged Me.BindingContext(dsPasswordList, "PasswordList").EndCurrentEdit() If Me.BindingContext(dsPasswordList, "PasswordList").Position<> -1 And Not mlLoading Then dsPasswordList.PasswordList.Rows(Me.BindingContext (dsPasswordList, "PasswordList").Position).Item("DepartmentID") = Me.cboPasswordListsDepartment.SelectedValue End If End Sub Private Sub DsPasswordList_PositionChanged() Me.BindingContext(dsPasswordList, "PasswordList").EndCurrentEdit() If Me.BindingContext(dsPasswordList, "PasswordList").Position<> -1 And Not mlLoading Then Me.cboPasswordListsDepartment.SelectedValue = dsPasswordList.PasswordList.Rows(Me.BindingContext (dsPasswordList, "PasswordList").Position).Item("DepartmentID") End If End Sub ''End of Position Changed Code - Password Lists ''PasswordLists Code Start Private Sub btnPasswordListsDelete_Click(ByVal sender AsSystem.Object, ByVal e As System.EventArgs) Handles btnPasswordListsDelete.Click If MessageBox.Show("Are Your Sure You Want To Delete?", "WARNING!!!!", MessageBoxButtons.OKCancel) = DialogResult.OK Then If (Me.BindingContext(dsPasswordList, "PasswordList").Count >0) Then Me.BindingContext(dsPasswordList, "PasswordList").RemoveAt(Me.BindingContext(dsPassw ordList, "PasswordList").Position) End If End If End Sub Private Sub btnPasswordListsAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPasswordListsAdd.Click ''Reset Combo Box`s - Select Index Twice due to M 这篇关于DataRow - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-12 05:53