.MDB AutoNumber奇怪的行为 [英] .MDB AutoNumber strange behavior

查看:72
本文介绍了.MDB AutoNumber奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在成功绑定source.AddNew(),. EndEdit(),TableAdapter.Update()之后,我试图从新添加的记录中获取PrimaryKey的值,总是= -1!

After a successfull bindingsource.AddNew(), .EndEdit(), TableAdapter.Update(), i'm trying to get the value of the PrimaryKey from the newlly added record wich is always = -1!


 Private Sub BtnNewClient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNewClient.Click
  If BtnNewClient.Tag = "New" Then
   SetClientLayout(ClientLayouts.CLNew)
   Me.ClientsBindingSource1.AddNew()
  Else
   Try
    Me.Validate()
    Me.ClientsBindingSource1.EndEdit()
    Me.ClientsTableAdapter.Update(PsEstimationsDataSet.Clients)
    Me.ClientsBindingSource1.ResetBindings(False)
    Me.ClientIDFromEstim.Text = IDLabel.Text
    SetClientLayout(ClientLayouts.CLDefault)
   Catch ex As Exception
    MsgBox("Update failed " & Chr(13) & ex.Message)
   End Try
  End If

 End Sub

推荐答案

首先,这个论坛是有关Visual Studio帮助系统和开发人员文档的讨论,您的问题最好放在Visual Basic论坛中,例如:

First, this forum is for discussions on the Visual Studio Help system and developer documentation, your question would be better placed in a Visual Basic forum such as this one:

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/threads

要解决您的问题,请在检索键值之前尝试在BindingSource实例上调用MoveLast方法。这将把索引定位在最后一个(最近插入的)行上,其中Current属性将指向您想要的键值。

To solve your issue, try calling the MoveLast method on your BindingSource instance before retrieving the key value. That will position the index on the last (most recently inserted) row, where the Current property will point to the key value you want.

http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource_members.aspx

 


这篇关于.MDB AutoNumber奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆