自动生成用于插入操作的ID [英] AutoGenerate Id For Insert Operation

查看:64
本文介绍了自动生成用于插入操作的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用3层体系结构将数据插入数据库..
但是我的问题是如何自动生成prod_id而不输入文本框或标签.
页面加载时会自动更改.
请解决方案

您的数据库可以为您生成顺序ID.

1)在数据库中创建一个ID列(我猜您正在使用MS SQL,因为您只声明了C#).
2)在ID列上将Identity列设置为true
3)在ID列上将Autoincrement设置为true

ID列值将根据数据库中的现有项目自动创建,并且您将获得序列1,2,3,..作为产品ID.此列也可以成为您的学生"表的主键.


您应使用 ^ ] Transact-Sql属性,用于为表定义一个标识列.您无需在标识"列中插入值.我会在您的表格栏中自动插入一个跑步号码.
请参考链接,例如:
身份列 [ SQL Server中的IDENTITY列 [ 解决方案

Your database can generate the sequential IDs for you.

1) Create an ID column in your database (I am guessing you are using MS SQL because you stated only C#).
2) Set Identity column to true on the ID column
3) Set Autoincrement to true on the ID column

The ID column value will be created automatically based on existing items in the database and you will get a sequence 1,2,3,.. for your product IDs. This column can also become the primary key for your Students table.


You should use IDENTITY[^] property of Transact-Sql to define an identity column for the table. You don''t need to insert values in identity column. I''ll automatically insert a running number in your table column.
Refer the links for example:
Identity Columns[^]
IDENTITY columns in SQL Server[^]


All the best.
--Amit


这篇关于自动生成用于插入操作的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发语言最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆