0

我只想增加 id 插入的限制等于其他表

对于那件事我没有任何疑问

唯一的问题是,我不能在 id 上增加代码直到限制

标识列 2

1-----------0

2-----------5

3-----------0

依此类推,像这样,通过单击插入按钮,id 应该逐个递增直到限制

谁能帮帮我吗

    RecordDate.Text = MyFormat

    Dim antinull As Integer = Format(0)
    BadBeg.Text = antinull
    WarePcs.Text = antinull
    CustPcs.Text = antinull
    Returned.Text = antinull
    BadEnd.Text = antinull

   Try
        Str = "insert into BadWarehouseInv values("
        Str += Id.Text.Trim()
        Str += ","
        Str += """" & RecordDate.Text.Trim() & """"
        Str += ","
        Str += """" & BadBeg.Text.Trim() & """"
        Str += ","
        Str += WarePcs.Text.Trim()
        Str += ","
        Str += CustPcs.Text.Trim()
        Str += ","
        Str += Returned.Text.Trim()
        Str += ","
        Str += """" & BadEnd.Text.Trim() & """"
        Str += ")"
        Con.Open()
        Cmd = New OleDbCommand(Str, Con)
        Cmd.ExecuteNonQuery()
        Dst.Clear()
        Dad = New OleDbDataAdapter("SELECT * FROM BadWarehouseInv ORDER BY Id", Con)
        Dad.Fill(Dst, "stock")

        Con.Close()
    Catch ex As Exception
        MessageBox.Show("Could Not Insert Record!!!")
        MsgBox(ex.Message & " -  " & ex.Source)
        Con.Close()
4

1 回答 1

0

我不确定我是否理解您的问题,但是:-

通常,当您写入数据库时​​,您有一列是Identity 类型,并且是表或Primary Key中的唯一标识符。当添加新行时,它会自动增加。

所以当你在表中创建一个新行时,你让数据库引擎担心这个,然后使用一种技术来读回这个值

如果您不想使用标识列,则可以使用查询来查找当前的最高数字,然后将其添加到其中。不建议这样做,因为您可能有两个客户端同时执行此操作,因此一个在尝试写入数据库时​​会失败。

于 2013-03-22T10:29:47.667 回答