我需要使用在switch case中为我的存储过程分配的变量,但我总是得到意想不到的结果。请帮助..任何回复都会很有帮助。谢谢。
private void CheckMessage()
{
string chk = null;
ShortMessage l = new ShortMessage();
string strCommand = "AT+CMGL=\"ALL\"";
objShortMessageCollection = objclsSMS.ReadSMS(this.port, strCommand);
foreach (ShortMessage msg in objShortMessageCollection)
{
l.Message = msg.Message;
string[] splt = l.Message.Split('#');
for (int i = 0; i < splt.Length; i++)
{
string[] parts = splt[i].Split(':');
char prefix = Convert.ToChar(parts[0]);
string value = parts[1];
switch (prefix)
{
case 'T':
l.truck = value;
break;
case 'D':
l.driver = value;
break;
case 'R':
l.receiveby = value;
break;
case 'A':
l.arrivedate = value;
break;
case 'U':
l.unloaddate = value;
break;
case 'N':
l.deliverynote = value;
break;
case 'L':
l.deliverydate = value;
break;
case 'S':
l.deliverystatus = value;
break;
case 'M':
l.mac = value;
break;
case 'C':
l.msgcreatedate = value;
break;
}
}
chk = l.getINFO(l).Tables[0].Rows[0][0].ToString();
if (chk == "1")
{
this.AutomaticReply();
this.DeleteToSim();
}
else
{
this.DeleteToSim();
}
l = null;
}
}
#endregion
这是我的存储过程..
ALTER PROCEDURE [dbo].[Message_Check]
@truck nvarchar(20),
@driver nvarchar(20),
@deliverynote int
AS
BEGIN
SELECT 1 FROM Truck trk, Driver drv, DeliveryNotes dnt
WHERE trk.Plate_Number = @truck
AND drv.DRIVER_ID = @driver
AND dnt.DNID = @deliverynote
AND dnt.Status = 'N'
END
答案 0 :(得分:1)
您的查询将输出1 .....总是
SELECT 1 FROM Truck trk, Driver drv, DeliveryNotes dnt
WHERE trk.Plate_Number = @truck
AND drv.DRIVER_ID = @driver
AND dnt.DNID = @deliverynote
AND dnt.Status = 'N'
应该是
SELECT Top 1 * FROM Truck trk, Driver drv, DeliveryNotes dnt
WHERE trk.Plate_Number = @truck
AND drv.DRIVER_ID = @driver
AND dnt.DNID = @deliverynote
AND dnt.Status = 'N'
答案 1 :(得分:0)
一种可能性是你所看到的角色不是资本,或者你可能正在获得领先的空间。看看这样的事情是否有帮助:
char prefix = parts[0].Trim().ToUpper()[0];
如果仍有问题,请编辑原始帖子并添加ShortMessage类的结构
答案 2 :(得分:0)
请通过检查传递给存储过程的值来使用断点和调试。
值可能有额外的空格,例如“aa bb”使用 TrimEnd(' ');
函数修剪结束值,&amp;请解析正确使用其数据类型(Int , Double , DateTime etc
)。您正在阅读的短信和其他用途的短信。请检查呼叫是否为私人/公共,以便将其值发送到存储过程。
char prefix = Convert.ToChar(parts[0]);
使用
parts[0]=parts[0].ToUpper();
char prefix = Convert.ToChar(parts[0]);
继续尝试......