主键外键引用 [英] primary key forigen key refernce

查看:127
本文介绍了主键外键引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


这篇关于主键外键引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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