输入字符串格式不正确 [英] Input string is incorrect format

查看:115
本文介绍了输入字符串格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int num = Convert.ToInt32(dataGridView1.Rows [i] .Cells [STUDENT NO]。Value.ToString());

cmd.Parameters.AddWithValue(@ STUDENT_NO ,num);



我尝试过:



cmd。 Parameters.Add(@ STUDENT_NO,SqlDbType.INT).Value = STUDENT_NO;在这个代码上我也得到一个错误

int num = Convert.ToInt32(dataGridView1.Rows[i].Cells["STUDENT NO"].Value.ToString());
cmd.Parameters.AddWithValue("@STUDENT_NO", num);

What I have tried:

cmd.Parameters.Add("@STUDENT_NO", SqlDbType.INT).Value = STUDENT_NO; on this code i also got an error ""

推荐答案

嗯,这是调试器会告诉你发生了什么的地方。你必须找出你想要转换为整数的单元格中的内容。



空单元格,空字符串或DbNull值不会转换为任何单元格整数,甚至不是0.现在你必须弄清楚为什么那个单元没有你期望的值。
Well, this is where the debugger will tell you what's going on. You have to find out what's in that cell you're trying to convert to an integer.

An empty cell, empty string, or DbNull value will not convert to any integer, not even 0. Now you have to figure out why that cell doesn't have the value you expect.


Quote:

输入字符串格式不正确



此错误消息告诉您问题不是您的代码,而是您尝试转换的值。

了解正在发生的事情的唯一方法是使用调试器并在发生故障时检查变量。一旦您知道哪些数据会导致代码失败,您就可以对代码进行更改。

< Update>

当嵌套代码出现问题时,请使用临时代码变量以查看每个嵌套级别的内容。

< / Update>



有一个工具可以让你看看你的代码在做什么,它的名字是调试器。它也是一个很好的学习工具,因为它向你展示了现实,你可以看到哪种期望与现实相符。

当你不明白你的代码在做什么或为什么它做它做的时候,答案就是答案是调试器

使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量。



调试器 - 维基百科,免费的百科全书 [ ^ ]

在Visual中调试C#代码工作室 - YouTube [ ^ ]

调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它不是'找到错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。


This error message tells you that the problem is not your code, but is in the value you try to convert.
The only way to know what is going on, is to use the debugger and inspect variables at point of failure. Once you know what data makes your code fail, you will be able to make changes to your code.
<Update>
When problem is in nested code, use temporary variables to see what is going on in each level of nesting.
</Update>

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]
Debugging C# Code in Visual Studio - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于输入字符串格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆