我收到Url
值的强制转换错误。有谁知道如何将值转换为包含多个值类型的字符串?
CmdRecipients = new OleDbCommand(QueryRecipients, ConnRecipients);
Recipients = CmdRecipients.ExecuteReader();
while (Recipients.Read())
{
Url = "https://bulktext.vodafone.ie/sendmessage.aspx"
+ "?user=user&password=user1!&api_id=89&to="
+ Recipients.GetString(8)
+ "&text=" + Confirmations.GetString(4)
+ "%0d%0a" + Confirmations.GetString(5)
+ "%0d%0a" + Confirmations.GetString(6)
+ "&from=Service";
Console.Write("Sending text to " + Recipients.GetString(8) + " ... ");
//Send SMS Here
HttpWebRequest req = WebRequest.Create(Url) as HttpWebRequest;
string result = null;
using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
if (result == "0\nRequest deferred successfully")
{
QueryRecipients = "UPDATE [Test].[dbo].[MessagesToSend] SET Previous_Status = Current_Status,"
+ "Current_Status = \"Sent\", DateTime_sent = Now() "
+ "WHERE Task_ID = \"" + Recipients.GetString(2) + "\";";
OleDbCommand Update = new OleDbCommand(QueryRecipients, ConnConfirmations);
Update.ExecuteNonQuery();
Console.WriteLine("Done!");
}
else
{
Console.WriteLine("The text wasn't delivered properly.");
}
}
}
答案 0 :(得分:0)
您的问题有点模糊,因为您没有告诉我们抛出异常的位置,也不知道异常是什么。
我怀疑问题在于您使用Confirmations.GetString(x)
和Recipients.GetString(x)
。据我所知,这些是数据库调用的结果。如果select返回的相应字段不包含字符串,则GetString
调用将失败。您需要使用与字段类型匹配的方法,例如GetBoolean
,GetInt32
等。