如何比较文本框值声明为varchar,并依赖其结果禁用其他文本框。 [英] how to compare a textbox value declare as varchar, and depeding on its result disable other textbox.

查看:69
本文介绍了如何比较文本框值声明为varchar,并依赖其结果禁用其他文本框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i想要将文本框值与> =运算符比较

如果textbox1.value> = 15000则禁用页面上的其他两个文本框。

但我在数据库中将此变量声明为varchar。



我该如何实现这个。



请帮忙。



谢谢

解决方案

首先是:使用正确的存储信息时的数据类型。如果是数字,请使用适当的数字数据类型。它在空间方面更有效率,这意味着你可以进行数学运算,例如与它们进行比较。



当你把东西存储为字符串时,你会得到字符串比较:这意味着逐个比较每个角色,第一个差异控制整个比较。因此,存储为字符串的数值的顺序是错误的:

 1 
10
11
12
...
19
2
20
...

它变得更糟:文本框可以包含非数字数字,所以你也必须允许您的用户输入hello作为订单数量...



在进行比较之前,您必须将字符串值转换为数字。


  if (!string.IsNullOrEmpty(textbox1.Text))
{
int value = 0 ;

bool isParsed = int .TryParse(textbox1.Text, out value );

if (isParsed&& value > = 15000
{
// 禁用其他TextBox。
}
}


如果你不想更改数据库中的数据类型,只是为了进行比较,将textbox String数据类型转换为Numeric数据类型并按照您的意愿执行,然后如果要将该文本框值存储在数据库中,则只存储该String类型数据。

hi ,
i want to compare a textbox value with >= operator like
if textbox1.value >= 15000 then disable other two textbox on page.
but i declare this variable in database as varchar.

how can i implement this.

pls help.

thanks

解决方案

The first thing is: use the correct datatype when you store information. If it is a number, use an appropriate numeric datatype. It's more efficient in terms of space, and it means that you can do math operations such as comparisons with them.

When you store things as strings, you get string comparisons: which means each character is compared one by one and the first difference controls the whole comparison. So the "order" of numeric values stored as string is "wrong":

1
10
11
12
...
19
2
20
...

ANd it gets worse: Textboxes can contain non-numeric digits, so you also have to allow for your user entering "hello" as an order quantity...

You will have to convert your string values to numbers before you do the comparisons.


if(!string.IsNullOrEmpty(textbox1.Text))
{
    int value = 0;
    
    bool isParsed = int.TryParse(textbox1.Text, out value);
    
    if (isParsed && value >= 15000)
    {
        // Disable other TextBoxes.
    }
}


If you don't want to change datatype in your database, Just for comparison purpose convert the textbox String datatype to Numeric datatype and do as you like, Then if you want to store that textbox value in database then store that String type data only.


这篇关于如何比较文本框值声明为varchar,并依赖其结果禁用其他文本框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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