如何使数据库插入ID,而不是创建重复的记录. [英] How do I make a database insert id instead of creating duplicate records.

查看:104
本文介绍了如何使数据库插入ID,而不是创建重复的记录.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在软件调用ironspeed designer中创建一个使用记录控件的Web应用程序.

我设计了一个页面,并将其命名为addnarrativepage.aspx,该页面连接到表,表名是项目和叙述.在项目表中插入所有项目信息,该信息为每个条目创建一个projectID.我在addnarrativepage.aspx页上从项目表projectname列中创建了一个数据驱动的下拉列表框,以填充该列表.

我遇到的问题是,当我单击页面上的保存"或保存并新建"按钮时,它会创建一个新条目,而不是使用项目名称=项目ID作为参考,仅将项目ID添加到叙述表列narrative.projectID列中.

我的数据库表是:

项目与叙事

项目专栏是:
project_id PK
projectName
projectNumber

叙事栏为:
narrative_id PK
project_id FK

摘要
EM1
EF2
EE3

页面设计

月(input.textbox)
Project_Name(下拉列表框)
摘要(input.textbox)
EM1(input.textbox)
EF2(input.textbox)
EE3(input.textbox)

保存(按钮)
保存并新建(按钮)
取消(取消)


在新记录上同时使用两者在编辑时使用更新

我已将其设置为自动增量,并且已设置了标识列

我创建了一个自定义存储过程,以查看这是否可以解决我的问题,但不走运


我要问的是是否有表格显示项目名称

I create a web application in software call ironspeed designer that use record controls.

I design a page and called addnarrativepage.aspx which join to tables, table names are project and narrative. The project table is where all project information is inserted which creates a projectID for each entry. I create on the addnarrativepage.aspx page a data driven drop down list box from the project table projectname column to populate the list.

The problem I having is that when I click the save or save and new button on the page it creating an new entry instead using the project name = project ID as a reference to add just the project id into the narrative table column narrative.projectID column.

My database table are:

Projects and Narrative

projects columns are:
project_id PK
projectName
projectNumber

Narrative columns are:
narrative_id PK
project_id FK
Month
Summary
EM1
EF2
EE3

design of page

Month (input.textbox)
Project_Name (dropdown.Listbox)
Summary (input.textbox)
EM1 (input.textbox)
EF2 (input.textbox)
EE3 (input.textbox)

Save (button)
Save and New (button)
Cancel (cancel)


using both on new record insert on edit I using update

I have it set for auto-increment and I have identity column set

I created a custom stored procedure to see if this would fix my problem no luck


all I am asking is there away form me to show the project name

推荐答案

了解您的问题很困难.
好的,解决您的问题的方法是:
1.您需要放置必填字段验证器.
2.放入业务逻辑以检查重复记录
一个.您可以使用代码逻辑在插入
之前检查重复的记录 b.如果某些东西在字段级别是唯一的,则还要在数据库中放置一个UNIQUE键约束
3.进行以ProjectID而不是name为参数的SQL查询.
It was little difficult understanding what your problem was.
Okay so, resolution to your issue is:
1. You need to put required field validators.
2. Put business logic to check duplicate record
a. you can have a code logic to check duplicate records before inserting
b. if something is field level unique, also put a UNIQUE key constraint in your DB
3. Make your SQL query that takes ProjectID and not name as a parameter.


OP太长了!
您需要正确规范化数据库.
使用代理键(例如,您的自动递增ID字段)会导致您需要做额外的工作以确保唯一性(以及其他问题).参见:

http://en.wikipedia.org/wiki/Surrogate_key#Disadvantages_of_Surrogate_Keys [
The OP is too long!
You need to normalise you database properly.
Using Surrogate keys (such as your auto-incrementing ID Field) has the effect that you need to do extra work to ensure uniquness (amongst other problems). See:

http://en.wikipedia.org/wiki/Surrogate_key#Disadvantages_of_Surrogate_Keys[^]

If the project information relies on the ProjectName, use that as the primary key. If it relies upon the ProjectName and Reference, use these etc. If you apply this consistently across the tables, you''ll find your task easier. If you use surrogate keys, to do a good job you''ll end up re-implementing the referential integrity stuff (like Sandeep''s answer) SQL servers already do really well for free.


使用保存"按钮运行的代码是什么?您要运行插入查询而不是更新查询吗?
What code are you running with the Save button? Are you running an Insert query instead of an Update query?


这篇关于如何使数据库插入ID,而不是创建重复的记录.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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