不能隐式转换类型'string'& # 39; int # 39;在linnworks
本文关键字:int linnworks 不能 转换 string 类型 | 更新日期: 2023-09-27 18:04:29
我在我的脚本上停留了一行,并且不断获得不能隐式地将类型字符串转换为int在第48行返回shipping,我不太确定为什么会出错,但只是试图检索以检查shipping文本,看看它是否说UK Next
namespace linnworks.finaware.CommonData.Objects // leave untouched
{ // leave untouched
public class ScriptMacroClass : linnworks.scripting.core.IOrderScript // leave untouched
{ // leave untouched
public void Initialize(linnworks.finaware.CommonData.Objects.Order order,linnworks.scripting.core.Debugger debug) // leave untouched
{ // leave untouched
}
public int getShipping(linnworks.finaware.CommonData.Objects.Order order)
{
string xml = "";
string shipping = "";
string query = @"
Select ox.ObjectXml
FROM [Order] o
INNER JOIN OrderXml ox ON ox.fkOrderId = o.pkOrderID
WHERE o.pkOrderID = @OrderID
";
using (SqlConnection conn = new SqlConnection(order.GetConnectionString))
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@OrderId", order.pkOrderID);
using (XmlReader reader = cmd.ExecuteXmlReader())
{
//loop over XML to find the nodes we want
while (reader.ReadToFollowing("OrderWithItems"))
{ //root node
while (reader.ReadToFollowing("ShipServiceLevel"))
{ // buyer node with child elements
{ //the node we want, get it as an string
shipping = reader.ReadElementContentAsString();
}
}
}
}
conn.Close();
}
return shipping;
if (shipping == "UK Next")
{
order.Marker = 2;
order.Save(0);
}
} // leave untouched
public string Filter(){ // leave untouched
/*Optional: Specify your order filter in query variable, must be SQL Statement that outputs pkOrderId column ONLY*/
string query="";
return query;
}
} // leave untouched
}
您将getShipping
函数定义为返回int
,实际上,return
甚至在函数结束之前返回string
。实际上,该函数将在return
上停止执行,并且这部分代码将永远不会执行:
if (shipping == "UK Next")
{
order.Marker = 2;
order.Save(0);
}
你应该检查你是否应该返回一个int
,因为我看到代码甚至没有对整数进行操作。