System.FormatException:'输入字符串的格式不正确。'数据网格

问题描述 投票:-4回答:1

当我运行应用程序时,它显示没有错误。从MySql加载datagridview并按下导致上述功能的按钮后,显示错误。

Error

int SMSLineID = 0;
List<SendMessageWebSerrvice.WebServiceSmsSend> SendDetail = new List<SendMessageWebSerrvice.WebServiceSmsSend>();
{
    string MessageBody = string.Empty;
    long MobileNo = 0;
    bool IsFlash = false;
    foreach(DataGridViewRow dataGridViewRow in dgvShowUsers.Rows)
    {
        DataGridViewCheckBoxCell Checking = dataGridViewRow.Cells["colSelect"] as DataGridViewCheckBoxCell;
        if (Convert.ToBoolean(Checking.Value) == true)
        {
            MessageBody = "User of " + dataGridViewRow.Cells[1].Value.ToString() + " " + dataGridViewRow.Cells[2].Value.ToString() + " " + txtMessage.Text;
            MobileNo = Convert.ToInt64(dataGridViewRow.Cells[3].Value);
            IsFlash = false;
            SendDetail.Add(new SendMessageWebSerrvice.WebServiceSmsSend(){
                MessageBody = MessageBody,
                MobileNo = MobileNo,
                IsFlash = IsFlash
            });
        }
    }
}
if (!int.TryParse(txtLineSerial.Text, out SMSLineID)) throw new Exception("Error");
SendMessageWebSerrvice.SendReceive WS = new SendMessageWebSerrvice.SendReceive();
string Message = null;
long[] Result = WS.SendMessage(txtUserName.Text.Trim(), txtPassword.Text.Trim(), SendDetail.ToArray(), SMSLineID, null, ref Message);
if (!string.IsNullOrWhiteSpace(Message)) throw new Exception(Message);
MessageBox.Show("OK");
return;

我的网格视图电话号码是3。

c#
1个回答
1
投票

请不要发布图片。关于你的问题,因为你的输入有一些字符不是数字所以系统无法解析它。您应该使用此方法而不是当前的方法:

Int64.TryParse($"{dataGridViewRow.Cells[3].Value}", out long value);

© www.soinside.com 2019 - 2024. All rights reserved.