我想将数据插入到数据库表:我怎样才能解决这个错误的C#
myCommand.CommandText = "INSERT INTO Selectionner (IdPrestation,
IdPhrase, DegreUrgence,RisqueConcerne,rowguid,Cotation) " +
"VALUES ('" +new Guid(emp.IdPrestation) +
"', '" +new Guid(emp.IdPhrase)+ "', '" +
emp.DegreUrgence + "','" + emp.RisqueConcerne + "','" +
new Guid(emp.rowguid) + "','" + emp.Cotation + "')";
但这返回一个错误:
Guid should contain 32 digits with 4 dashes
(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
我怎样才能解决这个问题?
,不要串联SQL字符串,但使用的参数,以避免SQL注入和解析错误。我们需要以下变量的值来回答你的问题:'emp.IdPrestation','emp.IdPhrase','emp.rowguid'。你正在使用它们来初始化'GUIDs',它必须包含32个数字并且有4个破折号(错误是不言自明的,不是吗?)。 –
您可以给emp.IdPrestation,emp.IdPhrase和emp.rowguid一些示例值吗? – SWeko