Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
2
Answers
Ado.net dataset no primary key violation
Ashish Khandelwal
13y
2.2k
1
Reply
I am using dataadapter to fill dataset from a table with primary key. When I made changes in dataset for duplicate value in that column it doesn't display primary key violation. Also it accept changes with dataset's accept change command. My question is why it doesn't display primary key violation . Whether dataset doesn't keep primary key from its source table? and need to explictly make it primary key. If dataset doesn't accept primary key then why dataadapter shows its inability to delete records if fill data from table without primary key.
string sqlcommand = "select * from itemmaster";//itemaster contains id field which is primary key//
SqlConnection
cn
=
new
SqlConnection
(
connstring
);
cn
.
Open
();
SqlCommand
cmd
=
new
SqlCommand
(
sqlcommand
,
cn
);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet(); da.Fill(ds);
ds.Tables[0].Rows[4]["ID"] = "2"; // value 2 already exists in another row
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
How to handle the data base insert or updates in code behind page?
Query to find ClosingStock