WHERE子句附近出错。 [英] Error near WHERE clause is coming.

查看:84
本文介绍了WHERE子句附近出错。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WHERE子句即将发生错误。

这是我的代码。请检查。

Error near WHERE clause is coming.
This is my code. please check it.

protected void Button3_Click(object sender, EventArgs e) 
{     
    foreach(GridViewRow ro in GridView2.Rows)
    {
        foreach (GridViewRow row in GridView1.Rows)
        { 
            if (row.RowType == DataControlRowType.DataRow)
            {
                Label Role = (ro.Cells[1].FindControl("Role_Name") as Label);
                CheckBox chkAdd = (row.Cells[2].FindControl("CheckBox1") as CheckBox);
                CheckBox chkEdit = (row.Cells[2].FindControl("CheckBox2") as CheckBox); 
                CheckBox chkView = (row.Cells[2].FindControl("CheckBox3") as CheckBox); 
                CheckBox chkDelete = (row.Cells[2].FindControl("CheckBox4") as CheckBox); 
                string strID = row.Cells[0].Text; 
                string Pages = row.Cells[1].Text;
                string Role_Name = ro.Cells[2].Text;
                con.Open();
                string query = "Insert Into  Role1  ([Role_Name],[Add],[View],[Edit],[Delete]) values('"+Role_Name+"','"+(chkAdd.Checked== true?'Y':'N')+"','"+(chkView.Checked==true?'y':'N')+"' ,'"+(chkEdit.Checked==true?'y':'N')+"' ,'"+(chkDelete.Checked==true?'y':'N')+"') WHERE ID='" +strID + "' and Pages ='"+Pages+"'" ; 
                SqlCommand cmd = new SqlCommand(query, con); 
                cmd.ExecuteNonQuery(); 
                BindGrid();
                
                con.Close();
              
            } 
        }
    }
}

推荐答案

INSERT语句没有WHERE子句 - 它们不会影响现有行,而是总是创建一个新行。



您需要完全删除WHERE子句,或者使用相反,UPDATE查询将更改与WHERE子句匹配的所有行,并且不会创建任何新行。
INSERT statements do not have a WHERE clause - they do not affect existing rows, they always create a new rows instead.

You either need to remove the WHERE clause completely, or use an UPDATE query instead, which will change all rows that match the WHERE clause, and do not create any new rows.


我认为您要更新记录而不是插入新的使用更新查询不插入
I think you want to update record and not insert a new use update query not insert


这篇关于WHERE子句附近出错。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆