Click here to Skip to main content
15,886,069 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
string ConnectionString = "User ID=SYSDBA;Password=masterkey;" + "Database=localhost:C:\\Documents and Settings\\manyam\\Desktop\\ITAS.FDB; " + "DataSource=localhost;Charset=NONE;";
Posted
Updated 5-Mar-12 1:14am
v5
Comments
Oshtri Deka 5-Mar-12 4:27am    
Can you please write your table schema?
amolpatil2243 5-Mar-12 4:29am    
is your table contains LVE_ID as primary key??
2011999 5-Mar-12 4:34am    
yes

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

SQL
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)


C#
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
 
Share this answer
 
Comments
2011999 5-Mar-12 5:34am    
not working
hi,

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
 
Share this answer
 
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
 
Share this answer
 
v3
Comments
2011999 5-Mar-12 5:06am    
not working
chandrasen singh 5-Mar-12 5:09am    
would you write table structure ???
2011999 5-Mar-12 5:17am    
above posted

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