Ado.net dataset no primary key violation

Sep 18 2011 1:22 AM


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




Answers (2)