c# - System.FormatException: '输入字符串的格式不正确。' 数据网格
问题描述
当我运行应用程序时,它没有显示任何错误。在我从 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;
我的网格视图电话号码是 3 。
解决方案
请不要张贴图片。关于您的问题,因为您的输入有一些字符不是数字,所以系统无法解析它。您应该使用这种方法而不是当前的:
Int64.TryParse($"{dataGridViewRow.Cells[3].Value}", out long value);
推荐阅读
- jquery - 使用 JQuery 不安全的内联和 CSP 的问题
- android - 如何在 nativescript 插件种子中实现 google play 服务?
- gsoap - gsoap如何防止枚举值的下划线翻译
- ruby - Logstash - 使用 ruby 代码计算持续时间
- fleetboard - 驾驶员分心受限状态如何工作?
- php - Laravel Passport:仅使用用户名而不使用密码登录
- mysql - 将 JobID 从 React&Redux 前端传递到 NodeJS 后端时,req.body.jobId 显示未定义?
- java - 如何解决“如果”总是“真”
- apache - 来自 htaccess 对 Web 请求的自定义响应
- php - Laravel 5.7:使用翻译字符串或键?