简体   繁体   English

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

[英]System.FormatException: 'Input string was not in a correct format.' data grid

When I run the application it displays no errors.当我运行该应用程序时,它没有显示任何错误。 After I load the datagridview from MySql and press the button that leads to the above function it displays error.从 MySql 加载 datagridview 并按下导致上述功能的按钮后,它显示错误。

错误

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;

My grid view phone number is 3 .我的网格视图电话号码是 3 。

Please do not post image.请不要张贴图片。 About your problem, because your input have some character isn't a number so system can't parse it.关于您的问题,因为您的输入有一些字符不是数字,所以系统无法解析它。 You should use this approach instead of the current:您应该使用这种方法而不是当前的方法:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.FormatException:输入字符串的格式不正确。 c# - System.FormatException: Input string was not in a correct format. c# System.FormatException: &#39;输入字符串的格式不正确。&#39; - System.FormatException: 'Input string was not in a correct format.' System.FormatException:&#39;输入字符串的格式不正确。 - System.FormatException: 'The input string does not have the correct format.' System.FormatException: '输入字符串的格式不正确。' WinForms - System.FormatException: 'Input string was not in a correct format.' WinForms “System.FormatException:输入字符串的格式不正确。” - "System.FormatException: Input string was not in a correct format." Linq 错误输入字符串的格式不正确。 System.Exception {System.FormatException} - Linq Error Input string was not in a correct format. System.Exception {System.FormatException} C# 错误 System.FormatException: &#39;输入字符串的格式不正确。&#39; 在数字输入上 - C# Error System.FormatException: 'Input string was not in a correct format.' on number input System.FormatException:输入字符串的格式不正确 - System.FormatException:Input string was not in a correct format uint.Parse 对有效字符串抛出 System.FormatException:“输入字符串的格式不正确。” - uint.Parse on a valid string throws System.FormatException: 'Input string was not in a correct format.' System.FormatException:输入字符串的格式不正确 - System.FormatException: Input string was not in a correct format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM