hi,
I have a table of student which contain four fields that
are id(primary key number) , name(text),seme ster(text)and
corse(text), When I insert values in a student
table.Explorer Show the follwing exception string.
"The changes you requested to the table were not
successful because they would create duplicate values in
the index, primary key, or relationship. Change the data
in the field or fields that contain duplicate data, remove
the index, or redefine the index to permit duplicate
entries and try again."
I am using different values in the code that are not
already exist in table.
The code for insertion is given below.
try
{
OleDbConnection con=new
OleDbConnection (@"provider=mic rosoft.jet.oled b.4.0 ; data
source=D:\Inetp ub\wwwroot\ado_ net\test.mdb");
string isql="INSERT INTO
student VALUES(14,'sam' ,'4th','ACCP')" ;
OleDbCommand ins=new
OleDbCommand(is ql,con);
ins.Connection. Open();
ins.ExecuteNonQ uery();
ins.Connection. Close();
}
catch(Exception ec)
{
Response.Write
(ec.Message.ToS tring());
}
Please solve my problem, i am using c# as code behind.
Thanks
Muhammad Usman. 1 1679
What is the hardcoded 14 . Check in the database if a 14
already exists in the database or not. I think if you
change the database field as type auto it should suffice
your purpose. -----Original Message----- hi,
I have a table of student which contain four fields that are id(primary key number) , name(text),seme ster(text)and corse(text), When I insert values in a student table.Explor er Show the follwing exception string.
"The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data,
removethe index, or redefine the index to permit duplicate entries and try again."
I am using different values in the code that are not already exist in table.
The code for insertion is given below.
try { OleDbConnection con=new OleDbConnectio n(@"provider=mi crosoft.jet.ole db.4.0 ; data source=D:\Inet pub\wwwroot\ado _net\test.mdb") ; string isql="INSERT INTO student VALUES(14,'sam' ,'4th','ACCP')" ; OleDbCommand ins=new OleDbCommand(i sql,con); ins.Connection. Open(); ins.ExecuteNonQ uery(); ins.Connection. Close(); } catch(Exception ec) { Response.Write (ec.Message.To String()); }
Please solve my problem, i am using c# as code behind.
Thanks
Muhammad Usman. . This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sugapablo |
last post by:
Let's say I create a new record in a table like this:
mysql_query("INSERT INTO table (col1) VALUES ('example')",$conn);
....that had an auto-incrementing, unique identifying column named "ID"
that would be populated with a unique number upon insertion...
How can I get the unique number it assigned to that record returned for
futher use?
|
by: Robert Stearns |
last post by:
I don't understand the reference "2" in the following message. There is
only a primary key constraint on the named table. It is generated by
default and Im not inserting a value for it.
SQL0803N One or more values in the INSERT statement, UPDATE statement,
or foreign key update caused by a DELETE statement are not valid because
the primary key, unique constraint or unique index identified by "2"
constrains table "IS3.ENTITIES_PUB" from...
|
by: frank |
last post by:
I posted a question before (to too many groups) and this time I am
sending to this group only. I have a quick script as seen below, the
file_list table has a unique field called file_name.
The problem I am having is that if no unique items exist, this will
insert into the table fine. But if a unique item does exist it will not
insert as it should. My problem is that I can not get access to return
any kind of error. This is very...
|
by: Charles Wilt |
last post by:
I have a IBM iSeries (aka AS-400) running v5r3 of OS/400 that I access
via a linked server from SQL Server 2000.
The following select works fine:
select * from prod400db.test.meldbf.InventoryHistory
However, this insert statement fails:
insert into prod400db.TEST.MELDBF.InventoryHistory
|
by: ing42 |
last post by:
I have a problem with inserting records into table when an indexed view
is based on it.
Table has text field (without it there is no problem, but I need it).
Here is a sample code:
USE test
GO
CREATE TABLE dbo.aTable (
INT NOT NULL
| |
by: Peter Newman |
last post by:
when I load a form I create a dateaset using
(part of sub )
Orig_Accounts = GetSQLDataSet("EXEC
BossData.dbo.SQL2005_ORIGACCOUNTS", "TBL_OrigAccounts")
' Set Primary Keys
SearchKey(0) =
Orig_Accounts.Tables("TBL_OrigAccounts").Columns("tblOA_Licence")
SearchKey(1) =
Orig_Accounts.Tables("TBL_OrigAccounts").Columns("tblOA_AccountID")
Orig_Accounts.Tables("TBL_OrigAccounts").PrimaryKey = SearchKey
|
by: Phil Latio |
last post by:
I am inserting data into user table which contains 5 fields, sounds simple
enough normally but 2 of the fields are designated as UNIQUE. If someone
does enter a value which already exists, how do I capture this specific
error?
Would it make more sense to actually run a SELECT query first and if that
returned a result, then I use that for error checking and don't run insert
until select returns nothing?
Cheers
|
by: Oonz |
last post by:
Hi Friends,
How can we insert records in sorted order
like consider a table
No Name Phone
1 test1 12345
1 test1 23455
2 test2 68638
|
by: franc sutherland |
last post by:
Hello,
I am using Access 2003. I am having trouble trapping the "can't
append all the records in the append query" error message when
appending data to a query from a table which is linked to an excel
spreadsheet.
There are two tables. One is a list of general contacts, and the
other is a list of clubs. The clubs contain members who are within
the contacts table. When I add a list of new club members from the
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |