Как проверить повторяющиеся значения и куда добавить код
SqlConnection con = new SqlConnection("Data source=SABITARAI-PC\\SQLEXPRESS; Initial Catalog=SRMAMSDB; user id=abc; password=sabita23"); string str, str2; str = "select *from tblUserRegistrationForm where User_Name='" + txtUserName.Text + "'and Password='" + txtPass.Text + "'"; SqlCommand cmd = new SqlCommand(str, con); SqlDataReader sdr; con.Open(); sdr = cmd.ExecuteReader(); if (sdr.Read()) { MessageBox.Show(" User already exists"); } else { sdr.Close(); str2 = "insert into tblUserRegistrationForm (User_name,Password,UserRole)values( '" + txtUserName.Text + "','" + txtPass.Text + "', '" + cmbUserRole.SelectedItem.ToString() + "')"; SqlCommand cmd2 = new SqlCommand(str2, con); cmd2.ExecuteReader(); txtUserName.Text = ""; txtPass.Text = ""; cmbUserRole.Text = ""; txtUserName.Focus(); } con.Close(); } this is my code What I have tried: <pre>SqlDataAdapter sda = new SqlDataAdapter(cmd.CommandText, con); DataTable dt = new DataTable(); sda.Fill(dt);
BillWoodruff
что же теперь не так ? есть ли сообщение об ошибке Энн ?