增加一个字段 [英] Incrementing a field

查看:102
本文介绍了增加一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用自动编号的情况下增加字段,

喜欢读取它的最后一个值然后递增它?

我是vb.NET的新手真的需要一个详细的解释。

How can I increment a field without using Autonumber,
like reading from its last value and then increment it?
I''m new to vb.NET and really need a detailed explanation.

推荐答案

我相信你在谈论数据库中字段的自动编号,对吧?在vb.net中,只需在查询上使用一个命令(如果你需要更多的东西就可以使用dataReader)

INSERT INTO yourTable SELECT((从你的表中选择count(*))+ 1 ),...


但要注意,当您从该表中删除一行时,COUNT(*)可能会返回已存在的索引并导致错误。


编辑:你也可以这样做(如果这是你想要的)


INSERT INTO yourtable SELECT((从你的表中选择MAX(yourTable_index))+1 ),...
I believe you are talking about autonumbers for fields in a database, right? In vb.net simply use a command (and a dataReader if you need more stuff) on a query like

INSERT INTO yourTable SELECT ((select count(*) from yourTable) + 1), ...

But be careful, when you delete a row from that table, the COUNT(*) might return an already existing index and cause an error.

you can also do (if this is what you wanted)

INSERT INTO yourtable SELECT ((select MAX(yourTable_index) from yourTable)+1),...


谢谢你的帮助。

我试过你给我的代码,但它似乎没有工作。

我不能存储ID也不会增加代码。

以下是我的代码,



列代码是因为我存储新的ID而增加的那个。


Hi, thank you for your kind help.
I have tried the code you gave me but it doesn''t seem to work.
Ican''t store the ID nor increment the Code.
Here are my codes below,


Column "Code" is the one that suppose to increment as I store new "ID".



展开 | 选择 | 换行 | 行号


展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号


这篇关于增加一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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