0

我收到该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.");
        }
    }
}
4

1 回答 1

0

您的问题有点含糊,因为您没有告诉我们异常是在哪里引发的,也没有告诉我们异常到底是什么。

我怀疑问题出在您对 and 的使用Confirmations.GetString(x)Recipients.GetString(x)。据我了解,这些是数据库调用的结果。如果 select 返回的各个字段不包含字符串,则GetString调用将失败。您需要使用与字段类型匹配的方法,例如GetBoolean,GetInt32等。

于 2013-11-08T10:03:46.560 回答