I am making timetable management.I want to display the table in grid view. I have done every thing except these data duplication is database.Repeated values should not accept in database.I have tried these below code but it is displaying duplicate values is there any problem in these code?
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Enfosys-8\Documents\Visual Studio 2012\Projects\NewTimeTable\NewTimeTable\App_Data\Admindetail.mdf;Integrated Security=True"))
{
con.Open();
SqlDataAdapter cmd = new SqlDataAdapter("select * from datelist where WeekMonth='" + txtmonth.Text + "' and subject='" + ddlsubject.SelectedValue + "' and daywk='" + ddlweek.SelectedValue + "' ", con);
DataTable dt = new DataTable("dt");
cmd.Fill(dt);
Gv3.DataSource = dt;
Gv3.DataBind();
}
}
using (SqlDataReader Reader = cmd.ExecuteReader())
{
if (Reader.HasRows)
{
throw new ApplicationException("data is duplicated");
}
}