ASP.NET ,, C# QUESTION :: I have the following web application structure:(image attached):: I have the following code for clicking the button "save" which saves the text written in the 3 text boxes into the 3 fields of the table `Trial` in database:
protected void AddProgramButton_Click(object sender, System.EventArgs e) { DataBinder ds = new DataBinder(); sqlcon.Open(); SqlCommand sqlcmd = new SqlCommand("INSERT INTO Trial VALUES (@FirstColumn, @SecondColumn , @ThirdColumn)", sqlcon); sqlcmd.Parameters.AddWithValue("@FirstColumn", RadTextBox1.Text); sqlcmd.Parameters.AddWithValue("@SecondColumn", RadTextBox2.Text); sqlcmd.Parameters.AddWithValue("@ThirdColumn", RadTextBox3.Text); sqlcmd.ExecuteNonQuery(); // lbl.Visible = true; sqlcon.Close(); }
My question is :: The column `FirstColumn` in the table `Trial` is primary key field. So, I don't want to save the data into the database directly , BUT I want it to first check the value I entered in `RadTextBox1` and see if it exists in the database or not :: - If it exists, then it will display the corresponding values in `RadTextBox2` and `RadTextBox3` - If it doesn't exist , then `RadTextBox2` and `RadTextBox3` will remain blank and allow user to enter new data. How can I do that ? I have been searching a lot but it is so confusing as I just started learning this. I reallyy appreciate your help.
Join our real-time social learning platform and learn together with your friends!