C# 分析查询时出错。[令牌行编号=1,令牌行偏移量=40,令牌出错=第一个]
我正在用sql做Csharp。但我也有错误 分析查询时出错。[令牌行编号=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
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后,把[第一名称]而不是名字和[帐户管理器]。