Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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";

}

}
Posted
Updated 9-Jan-14 17:59pm
v2

1 solution

objlinq.T_patient_registrations.InsertOnSubmit(objreg);

Not sure what this is. I'd add the object to the collection of objects on the DB, then save changes. You're not setting the id, so it should work, I'd refresh the EF DB definition and see what happens from there.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900