Click here to Skip to main content
15,905,614 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[2].FindControl("CheckBox1");
                if (chk != null)
                {
                    if (chk.Checked)
                    {
                        if (!Page.IsPostBack)
                        {
                            string strID = GridView1.Rows[i].Cells[0].Text;
                            string Pages = GridView1.Rows[i].Cells[1].Text;
                            string status = "Y";

                            SqlCommand cmd = new SqlCommand();
                            cmd = new SqlCommand("Update Role1  Set Add ='" + status + "' where ID= '" + strID + "'  and Pages= '" + Pages + "'", con);
                            con.Open();
                            cmd.ExecuteNonQuery();
                            con.Close();
                            GridView1.DataBind();
                        }
                    }
                    else
                    {



                        string strID = GridView1.Rows[i].Cells[0].Text;
                        string Pages = GridView1.Rows[i].Cells[1].Text;
                        string status = "N";
                        chk.Checked = false;

                        SqlCommand cmd = new SqlCommand();
                        //cmd = new SqlCommand("insert into Role1(Checkin_Add) values(" + status + " where ID= '" + strID + "' and Role_Name='" + strName + "')", con);
                        cmd = new SqlCommand("Update Role1  Set Add ='" + status + "' where ID= '" + strID + "'  and Pages= '" + Pages + "'", con);
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        GridView1.DataBind();
                    }

                }
Posted
Updated 13-Mar-14 23:47pm
v2

Maybe your column name "Add" is incorrect and should be "Checkin_Add" like in the commented line!?

Could you provide the SQL tables definitions details?
 
Share this answer
 
v2
Comments
Member 10578683 14-Mar-14 5:34am    
i have taken the column name Add in Role1 database
C#
cmd = new SqlCommand("Update Role1 Set [Add] =" + status + "' where ID=" + strID + " and Pages= '" + Pages + "'", con);

if Add,Id and Page are int type then Remove (' ') and if these are string type not remove
 
Share this answer
 
v3
hai

pls specify which line u get error ? bcz u have Add word in If part and also in Else part.pls check strID and Page field data type in ur database,is it nvarchar or integer,bcz u mention as strId and pages as string,what u get in this 2 fields ? any numbers or string ?

If it is integer in ur database then change as follows



C#
cmd = new SqlCommand("Update Role1 Set Add ='" + status + "' where ID= " + strID + " and Pages= " + Pages + "", con);



or try like this


C#
cmd = new SqlCommand("Update Role1 Set [Add] ='" + status + "' where ID= '" + strID + "' and Pages= '" + Pages + "'", con);


Give square bracket for [Add] column name,bcz Add,New,Date ect are predefined word in visual studio,u cant use same as a variable.

Try to change "Add" field name to any other name or give square bracket,best u rename Add to added or adding like this
 
Share this answer
 
v5
Comments
Member 10578683 14-Mar-14 5:32am    
In else part i m getting error near cmd.ExecuteNonQuery
Member 10578683 14-Mar-14 5:33am    
Incorrect syntax near the keyword 'Add'.
Aravindba 14-Mar-14 5:36am    
Try to give like this cmd = new SqlCommand("Update Role1 Set [Add] ='" + status + "' where ID= '" + strID + "' and Pages= '" + Pages + "'", con);

see my solution updated
Member 10578683 14-Mar-14 5:40am    
ya i did like this
it is executing
Member 10578683 14-Mar-14 5:40am    
It is now executing. but the if part is not executing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900