主键外键引用

编程入门 行业动态 更新时间:2024-10-23 07:35:37
本文介绍了主键外键引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

string ConnectionString = "User ID=SYSDBA;Password=masterkey;" + "Database=localhost:C:\\Documents and Settings\\manyam\\Desktop\\ITAS.FDB; " + "DataSource=localhost;Charset=NONE;";

推荐答案

您显然正在尝试将值输入到LVE_ID中,数据库(重复值),或者您试图在该字段中自动输入一个值.我还将提到,您应该使用参数化值,而不是连接字符串以生成sql查询.首先,这将防止您为该字段输入错误类型的值,并防止遭受sql注入攻击.这是参数化查询的意思的一个示例 You are obviously either trying to enter a value into LVE_ID that is already in the database (duplicate value) or you are trying to enter a value into this field where the field is meant to be auto generated. I will also mention that you should be using parameterised values instead of concatenating strings to produce your sql query. This will, first of all prevent you from entering values of the wrong type for the field as well as prevent you from suffering an sql injection attack. Here is a sample of what I mean by parameterised query INSERT into ATT_LVE (LVE_ID,LVE_EMP_ID,LVE_TYP_ID,LVE_BGNAT,LVE_ENDAT,LVE_REASON,LVE_BGN,LVE_END,LVE_STATUS,LVE_APPLIEDON)Values (@LVE_ID,@LVE_EMP_ID,@LVE_TYP_ID,@LVE_BGNAT,@LVE_ENDAT,@LVE_REASON,@LVE_BGN,@LVE_END,@LVE_STATUS,@LVE_APPLIEDON)

cmd.Parameters.AddWithValue("@LVE_ID", txtLeaveID.Text); cmd.Parameters.AddWithValue("@LVE_EMP_ID", txtEmpID.Text); cmd.Parameters.AddWithValue("@LVE_TYP_ID", ddlLeaveType.Text);

等 希望这对您有帮助

etc Hope this helps

如果您有 LVE_ID作为主键.然后将自动递增设为true.并且不要将文本框的值传递给LVE_ID.我认为它会起作用. 希望这对您有所帮助 If you are having LVE_ID as primary key. then make as auto increment true. and do not pass the text box value to LVE_ID. I think it will work. hope this may help you

似乎您的主键LVE_ID是整数(或非string),并且您通过''txtLeaveID.Text传递了字符串,因此必须覆盖txtLeaveID.文本为整数(通过使用 SqlDbType 类)或任何LVE_ID的数据类型. 就像 It seems your primary key LVE_ID is integer(or non string ) ,and you pass string by '' txtLeaveID.Text'' so you must have to coverty txtLeaveID.Text to integer (by using SqlDbType class) or whatever the datatype of LVE_ID is. like command.Parameters.Add("@ LVE_ID", SqlDbType.Int);

希望对您有所帮助

Hope this will help

更多推荐

主键外键引用

本文发布于:2023-10-18 11:11:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504072.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主键

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!