我有这个错误:必须声明标量变量“@Login”。
我的代码:
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["intranetv2"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("insert into [MyBase].[Dbo].[LogErrors] (Username, StackTrace, ShortDescription, DetailDescription, ErrorType) VALUES (@Login, @Stack, @Message, @Txt, @Source)", conn);
SqlParameter param = new SqlParameter();
param.ParameterName = "Login";
param.Value = user.Login;
param.ParameterName = "Stack";
param.Value = ex.StackTrace;
param.ParameterName = "Message";
param.Value = ex.Message;
param.ParameterName = "Txt";
param.Value = Txt;
param.ParameterName = "Source";
param.Value = ex.Source;
// 3. add new parameter to command object
cmd.Parameters.Add(param);
conn.Open();
return cmd.ExecuteNonQuery();
}
我尝试在参数中使用 th e'@' 但我有同样的错误。