当我试图跑但是错误
时,我遇到了这个错误描述:编译服务此请求所需的资源时发生错误。请查看以下特定错误详细信息并相应地修改源代码。
编译器错误消息:CS0029:无法隐式转换类型' string'到' int'
cmd.Parameters.AddWithValue("@pDateOfDelivery", po.dateOfDelivery);
cmd.Parameters.AddWithValue("@pStatus", po.status);
cmd.Parameters.AddWithValue("@pDeliveryTiming", po.deliveryTiming);
cmd.Parameters.AddWithValue("@pCoID", po.coID);
try
{
conn.Open();
int iResult = cmd.ExecuteNonQuery();
if (iResult > 0)
{
result = "You have successfully updated the DeliveryOrder!";
}
else
{
result = "You have encountered an error. Please try again.";
}
}
catch (Exception)
{
result = "You have encountered an error. Please try again";
}
finally
{
cmd.Dispose();
conn.Close();
}
}
}
return result;
}
答案 0 :(得分:0)
您的一个参数是期望int
类型,但您正在传递string
类型。
尝试下面在传递之前将字符串转换为int。
cmd.Parameters.AddWithValue("@pCoID", Int32.Parse(po.coID));
答案 1 :(得分:0)
使用Convert.ToInt32
方法将字符串变量转换为整数
cmd.Parameters.AddWithValue("@pCoID",Convert.ToInt32(po.coID));
答案 2 :(得分:0)