The local database has a User PersonName with the fields PersonName , PersonPass and ID(pk) . The ID uniqueidentifier data type and a default value ( newid() ). When I just add data to the table, the key is really unique, but when I use insert through a form using linq to sql insert in the database, something like 00000-000000 in the key field and when adding a new user, an error occurs because the second user in the key field the same zeros. What is causing this and how to fix it?
private void buttonRunReg_Click(object sender, EventArgs e) { using (DataClasses1DataContext db = new DataClasses1DataContext()) { User sequence = (from user in db.User where user.PersonName == textBox1.Text select user).SingleOrDefault(); if (sequence==null) { if ((textBox1.Text != "") && textBox2.Text.Equals(textBox3.Text)) { User userTable = new User(); userTable.PersonName = textBox1.Text; userTable.PersonPass = textBox2.Text; db.User.InsertOnSubmit(userTable); try { db.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } labelExForm2.Text = "регистрация прошла успешно"; labelExForm2.Visible = true; } else if (!textBox2.Text.Equals(textBox3.Text)) { labelExForm2.Text = "пароли не совпадают"; labelExForm2.Visible = true; } else { labelExForm2.Text = "Птушка не клюет зерно"; labelExForm2.Visible = true; } } else { labelExForm2.Text = "Имя "+textBox1.Text+" уже занято. попробуйте другое."; labelExForm2.Visible = true; } } } 