请在Add附近解决错误语法错误 [英] Please solve the error Incorrect syntax near Add

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

问题描述

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();
                    }

                }

推荐答案

也许您的列名添加不正确,应该是Checkin_Add就像在注释行中一样!?



你能提供SQL表定义细节吗?
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?


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



如果Add,Id和Page是int类型则删除(' ')如果这些是字符串类型不删除


if Add,Id and Page are int type then Remove (' ') and if these are string type not remove


hai



请指定哪条线路出错? bcz你有在if部分和在Else part.pls中添加单词检查ur数据库中的strID和Page字段数据类型,是nvarchar还是整数,bcz你提到strId和pages作为字符串,你在这2个字段中得到什么?任何数字或字符串?



如果它在你的数据库中是整数,那么改变如下







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



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







或尝试这样








or try like this


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





为[添加]列名称提供方括号,bcz添加,新建,日期等是预定义的单词视觉工作室,你不能使用相同的变量。



尝试将添加字段名称更改为任何其他名称或给出方括号,最好重命名添加到添加或者像这样添加



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


这篇关于请在Add附近解决错误语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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