Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 分析查询时出错。[令牌行编号=1,令牌行偏移量=40,令牌出错=第一个]_C#_Sql - Fatal编程技术网

C# 分析查询时出错。[令牌行编号=1,令牌行偏移量=40,令牌出错=第一个]

C# 分析查询时出错。[令牌行编号=1,令牌行偏移量=40,令牌出错=第一个],c#,sql,C#,Sql,我正在用sql做Csharp。但我也有错误 分析查询时出错。[令牌行编号=1,令牌行偏移量=40,令牌出错=第一个] private void CustomerAdded(Customer c) { string query = string.Empty; int rowsAffected = 0; try { if (connection.State != ConnectionState.Open

我正在用sql做Csharp。但我也有错误

分析查询时出错。[令牌行编号=1,令牌行偏移量=40,令牌出错=第一个]

private void CustomerAdded(Customer c)
    {
        string query = string.Empty;
        int rowsAffected = 0;
        try
        {

            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

query = string.Format("INSERT INTO CustomerRecord(CustomerId, First Name, Surname, PhoneNumber, City,Country, Account Manager) VALUES ({0},'{1}','{2}','{3}','{4}','{5}','{6}')",c.CustomerId,c.FirstName,c.Surname,c.PhoneNumber,c.City,c.Country,c.AccountManager);



 SqlCeCommand command = new SqlCeCommand(query, connection);

   rowsAffected = command.ExecuteNonQuery();(this is were the error say line 162)

        }
        catch (Exception ex)
        {
            MessageBox.Show("Error " + ex.ToString());
        }
        finally
        {
            connection.Close();
        }
        GetCustomers();
        bs.ResetBindings(false);
如果列名中有空格,则需要使用方括号。使用
[名字]
而不是
名字
[客户经理]
而不是
客户经理
。如果要向所有列插入值,则无需指定列名


你也应该考虑使用“防止代码> SQL注入< /代码>攻击。

你有SQL注入漏洞。谢谢你这么多SELMA22,是工作GGGGGGGGGGGG后,把[第一名称]而不是名字和[帐户管理器]。