为什么会这样呢! [英] Why is this happening!

查看:74
本文介绍了为什么会这样呢!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以即时创建一个窗口,基本上将输入的数据插入到SQL数据库中..



但这可能是一个简单的错误我在这里制作..但是出于某种原因,当我将文本框留空时,它仍然表示它有一个不正确的字符串输入。



这里是if语句,检查它是否为空值是不是。



Ok, so im creating a window that basically inserts the data entered into a SQL database..

But its probably a simple error im making here.. But for some reason when i leave a textbox blank, it still says that it has an incorrent string input.

here is the if statement of which checks it has a null value or not.

if (quantityAvailableTextBox.Text != null)
{ p.QuantityAvailable = Convert.ToInt32(quantityAvailableTextBox.Text); }
else { }





为什么会这样,再次,我确定它只是一个简单的解决方案...但由于某种原因,由于textbox.text为null的事实,它应该跳过并直接转到其他...但它通过if代码。



Why is this happen, again, im sure its a simply solution... But for some reason, because of the fact that the textbox.text is null it should skip and go straight to the else... but instead it goes through the if code.

推荐答案

使用 IsNullOrEmpty [ ^ ] < br $> b $ b

Use IsNullOrEmpty[^]

if (!string.IsNullOrEmpty(quantityAvailableTextBox.Text))
{
    p.QuantityAvailable = Convert.ToInt32(quantityAvailableTextBox.Text);
}
else { }


这篇关于为什么会这样呢!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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