本文介绍了违反主键约束pk_T_registration,无法在对象dbo.T_registration错误中插入重复键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我创建了一个注册表,其中pateintid作为主键,带有自动增量1.

i我使用linq提交我的deatails,如名称,性别....问题是,只有一个记录插入当我尝试插入上面的第二条记录时,表格开始以0为准,错误即将来临.......... plz给出一些想法



这里是我的代码



使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Web;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Data;

使用System.Data.SqlClient;

使用System.Configuration;



公共部分类PatientRegistration:System.Web.UI.Page

{



ADO objado = new ADO();

DataClassesDataContext objlinq = new DataClassesDataContext();

T_patient_registration objreg = new T_patient_registrati on();











protected void Page_Load(object sender,EventArgs e)

{



}



protected void Button1_Click(object sender,EventArgs e)

{

objreg.name = txtpatientname.Text;

objreg.father_mothername = txtguardianname.Text;

objreg.gender = drpgender.SelectedItem.ToString();

objreg.dateofbirth = txtdob.Text;

objreg .disease = txtdisease.Text;

objreg.age = Convert.ToInt32(txtage.Text);

objreg.emailid = txtemail.Text;

objreg.currentaddress = txtcaddress.Text;

objreg.city = drpcity.SelectedItem.ToString();

objreg.contactnumber = Convert.ToInt64(txtcontact.Text) ;

objreg.permanentaddress = txtpaddress.Text;

objreg.spe cialist = drpspecialist.SelectedItem.ToString();

objreg.occupation = drpoccupation.SelectedItem.ToString();

objlinq.T_patient_registrations.InsertOnSubmit(objreg);

objlinq.SubmitChanges();

Label1.Text =数据已成功插入;



}



}

i created one registyration table with pateintid as primary key with with autoincrement 1.
i am using linq to submit my deatails like name,gender....the problem was , only one record is inserting in the table starts pateintid with 0 when i try to insert second record above error is coming..........plz give some idea

here is my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class PatientRegistration : System.Web.UI.Page
{

ADO objado = new ADO();
DataClassesDataContext objlinq = new DataClassesDataContext();
T_patient_registration objreg = new T_patient_registration();





protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
objreg.name = txtpatientname.Text;
objreg.father_mothername = txtguardianname.Text;
objreg.gender = drpgender.SelectedItem.ToString();
objreg.dateofbirth = txtdob.Text;
objreg.disease = txtdisease.Text;
objreg.age = Convert.ToInt32(txtage.Text);
objreg.emailid = txtemail.Text;
objreg.currentaddress = txtcaddress.Text;
objreg.city = drpcity.SelectedItem.ToString();
objreg.contactnumber = Convert.ToInt64(txtcontact.Text);
objreg.permanentaddress = txtpaddress.Text;
objreg.specialist = drpspecialist.SelectedItem.ToString();
objreg.occupation = drpoccupation.SelectedItem.ToString();
objlinq.T_patient_registrations.InsertOnSubmit(objreg);
objlinq.SubmitChanges();
Label1.Text = "Data Inserted Successfully";

}

}

推荐答案


这篇关于违反主键约束pk_T_registration,无法在对象dbo.T_registration错误中插入重复键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 19:13