jeudi 16 avril 2015

How to use if statement in update query?

I want to block the checkbox when it is selected. I have admin and faculty page, and when admin block the particular checkbox it should block that particular check box to all faculties. These checkboxes are in grid. Each faculty have separate login, but all faculties have same grid. When one faculty block the particular checkbox it should blocked to other faculties also.


When I run the faculty page it block the particular checkbox which is already blocked by admin, then when I again submit from the faculty page it update all the old values with new values in test.db and it unblocked to other faculties also.


What I exactly need is when admin blocked the check box it should always blocked for all other faculty,when faculty also select some other check box and submit that particular check box should also blocked for all other faculty.


This is the code I used for update. But its not working



admin:

protected void Button2_Click(object sender, EventArgs e)
{
using (SqlConnection con2 = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=c:\users\work station\documents\visual studio 2012\Projects\NewTimeTable\NewTimeTable\App_Data\Admindetail.mdf;Integrated Security=True"))
{
string datedif = r.Cells[0].Text;
string dayweek = ddlclass.SelectedValue + ' ' + ddlmonth.SelectedValue + ' ' + ddlcourse.SelectedValue + ' ' + ddlsemester.SelectedValue + ' ' + ddlweek.SelectedValue;
con2.Open();
SqlCommand comm = new SqlCommand("insert into test (datedif,hour1,hour2,hour3,hour4,hour5,dayweek) values (@datedif,@hour1,@hour2,@hour3,@hour4,@hour5,@dayweek) ", con2);
comm.Parameters.AddWithValue("@datedif", datedif);
comm.Parameters.AddWithValue("@hour1", hour1);
comm.Parameters.AddWithValue("@hour2", hour2);
comm.Parameters.AddWithValue("@hour3", hour3);
comm.Parameters.AddWithValue("@hour4", hour4);
comm.Parameters.AddWithValue("@hour5", hour5);
comm.Parameters.AddWithValue("@dayweek", dayweek);
comm.ExecuteNonQuery();
con2.Close();
}
}


faculty:



protected void btnsubmit_Click(object sender, EventArgs e)
{
using (SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
string datedif = r.Cells[0].Text;
string subject1 = ddlsubjects.SelectedValue;
string subject2 = ddlsubjects.SelectedValue;
string subject3 = ddlsubjects.SelectedValue;
string subject4 = ddlsubjects.SelectedValue;
string subject5 = ddlsubjects.SelectedValue;
con2.Open();
SqlCommand comm = new SqlCommand("UPDATE test SET hour1 = @hour1,subject1 = @subject1,hour2 = @hour2,subject2 = @subject2,hour3 = @hour3,subject3 = @subject3,hour4 = @hour4,subject4 = @subject4,hour5 = @hour5,subject5 = @subject5 where datedif =@datedif and dayweek='"+ddlweek.SelectedValue+"'", con2);
comm.Parameters.AddWithValue("@hour1", hour1);
comm.Parameters.AddWithValue("@datedif", datedif);
comm.Parameters.AddWithValue("@subject1", subject1);
comm.Parameters.AddWithValue("@hour2", hour2);
comm.Parameters.AddWithValue("@subject2", subject2);
comm.Parameters.AddWithValue("@hour3", hour3);
comm.Parameters.AddWithValue("@subject3", subject3);
comm.Parameters.AddWithValue("@hour4", hour4);
comm.Parameters.AddWithValue("@subject4", subject4);
comm.Parameters.AddWithValue("@hour5", hour5);
comm.Parameters.AddWithValue("@subject5", subject5);
comm.ExecuteNonQuery();
con2.Close();
}
}


I want to use If statement in that update query. Suggest me how to do it.





Aucun commentaire:

Enregistrer un commentaire