累加编号时总是会卡在某个数上半天过不去符上程序段

VB.NET code
 Dim i As Integer

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
      
               Dim x As String
        connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\pigsystem\pigsystem\zmsf.mdb"
        Dim querystring As String = "Select top 1 编号 from zzlr order by 编号 desc "
        Dim conn As New OleDb.OleDbConnection(connectionstring)
        Try
            conn.Open()
            Dim cmd As New OleDb.OleDbCommand(querystring, conn)
            Dim reader As OleDb.OleDbDataReader
            reader = cmd.ExecuteReader()
            reader.Read()
            i = reader("编号")
            i = i + 1
        Catch ex As Exception
        End Try
        x = CStr(i)
        TextBox23.Text = x
        connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\pigsystem\pigsystem\zmsf.mdb"
        Dim querystring2 As String = "insert into zzlr(编号) values('" & x & "')"
        Dim conn2 As New OleDb.OleDbConnection(connectionstring)
        Try
            conn2.Open()
            Dim cmd2 As New OleDb.OleDbCommand(querystring2, conn2)
            cmd2.ExecuteNonQuery()
        Catch ex As Exception
        End Try
     End Sub


这段代码实现功能没有问题,点击Button7一次,表中插入一条新记录并且编号加1,并把编号反馈到TextBox23.Text中,只是在进行累加时,有时会卡到某个数上没有反应了,特别是点的很快时,比如到26,就停住了,没有反应了,点也不会再累加,这时如果退出再进程序,又会从26重新继续,或者如果不退出,狂点几下Button7也会跳过这个数就如同宕机一样。请高人指点看看是那个环节出了问题。

作者: zzc6913   发布时间: 2011-06-15

在一个过程中,数据库打开了两次吧?

作者: g12339645   发布时间: 2011-06-15

可是我试过放在同一段程序里,打开一次数据库,却不能实现累加。

作者: zzc6913   发布时间: 2011-06-15

没有关闭连接。conn.close();

作者: wjhgzx   发布时间: 2011-06-15