Possible Duplicate:
How to show a error message if the data is already inserted in the database in c#
protected void Button2_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection("Data Source=KING;Initial Catalog=semasinter;Integrated Security=True");
SqlCommand command = new SqlCommand("insert into StudentApplication", conn);
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "spinsertstudentapplication";
command.Parameters.AddWithValue("@Student_id", TextBox1.Text);/// in these student id is typed and inserted its a primary key
//command.Parameters.AddWithValue ("@Select_Course", ddlCourse.SelectedValue);
command.Parameters.AddWithValue("@Select_Country", TextBox4.Text);
command.Parameters.AddWithValue("@Select_State", TextBox2.Text);
command.Parameters.AddWithValue("@Select_Franchise", TextBox3.Text);
command.Parameters.AddWithValue("@Select_Sensei", ddlSensei.SelectedValue);
command.Parameters.AddWithValue("@Group", TextBox6.Text);
command.Parameters.AddWithValue("@Enter_Student_Name", TextBox7.Text);
command.Parameters.AddWithValue("@Enter_Student_Address", TextBox8.Text);
command.Parameters.AddWithValue("@Students_Father_Name", TextBox9.Text);
command.Parameters.AddWithValue("@Student_DOB", TextBox10.Text);
if (RadioButton2.Checked == true)
{
command.Parameters.Add("@Gender", SqlDbType.Bit).Value = true;
}
else
{
command.Parameters.Add("@Gender", SqlDbType.Bit).Value = false;
}
command.Parameters.Add("@Enter_Kyu", SqlDbType.NVarChar).Value = TextBox11.Text;
conn.Open();
int rows = command.ExecuteNonQuery();
conn.Close();
}
catch(Exception ex)
{
//.Show(ex.Message);
}
i want to show a error message that 'the student id is already inserted' nu friends i dono how to get it bcz student id id primary key