vb.net中的重复值 [英] duplicate value in vb.net

查看:70
本文介绍了vb.net中的重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i在我的代码下面几乎没有帮助,
当我点击支票时
不允许重复值盒子。

i完成了这个编码,但是当我点击复选框时我得到以下错误1

请查看下面的代码,让我知道它非常明显。

我的错误是:

从字符串转换为类型''布尔''无效。



我的代码是:

hi all,

i have few assistance in my code below,
am not allowing duplicate value when i was click on the check box.
i done this coding but am getting the below error when i have click checkbox1
please check out my code below and let me know its very appreciable.
my error is:
Conversion from string "" to type ''Boolean'' is not valid.

my code is:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


      Dim result As String
      Dim clsobj As clsCommon = New clsCommon
      result = clsobj.fncheck_email(CheckBox1.Checked = True)
      If result = CheckBox1.Checked = True Then     // this line am getting the above error
          MessageBox.Show("exits")
      Else

      End If
  End Sub





我的班级档案是:



clsCommon.vb:

公共职能fncheck_email(ByVal电子邮件)作为字符串)作为字符串

尝试

昏暗的结果作为字符串

con =新的SqlConnection(数据源= .\SQLEXPRESS;初始目录= test;用户ID = sa;密码= sa)

cmd =新SqlCommand(从deng中选择top 1 fev,其中fev =''+ email +'',con)

con.Open()

result = cmd.ExecuteScalar()。ToString()

返回结果

Catch generatedExceptionName As Exception

返回

结束尝试

结束函数



my class file is:

clsCommon.vb:
Public Function fncheck_email(ByVal email As String) As String
Try
Dim result As String
con = New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=test;User ID=sa;Password=sa")
cmd = New SqlCommand("select top 1 fev from deng where fev = ''" + email + "''", con)
con.Open()
result = cmd.ExecuteScalar().ToString()
Return result
Catch generatedExceptionName As Exception
Return ""
End Try
End Function

推荐答案

看看它抱怨的行:

Look at the line it is complaining about:
If result = CheckBox1.Checked = True Then     // this line am getting the above error



你有两个条件,只有三个操作数。因此编译器要么将其解释为:


You have two conditions, and only three operands. So either the compiler is to interpret it as:

If (result = CheckBox1.Checked) = True Then

或者作为

Or as

If result = (CheckBox1.Checked = True) Then

现在,因为CheckBox.Checked是一个布尔值,所以你不要需要检查它是否为True - 因为它已经是真或假。

结果是一个字符串,所以将它与bool进行比较是有点奇怪。



我不知道你在这里想做什么 - 你似乎没有使用结果再次这么说很难说 - 但我认为你需要首先考虑一下你的病情,然后尝试更清楚地写出来...... br $> b $ b



然后,你为什么要使用字符串呢?

为什么不使用数字? ?如果你的确实存在例程返回了现有电子邮件的整数,那么你不能只检查零吗?毕竟,ExecuteScalar返回一个数字......

Now, since CheckBox.Checked is a boolean value anyway, you don''t need to check it against True - because it is True or False already.
And result is a string, so comparing it against a bool is a little odd as well.

I''m not sure what you are trying to do here - you don''t appear to use result again so it''s difficult to tell - but I think you need to think about what you are trying to do with your condition first, then try to write it a little more clearly...


And then, there is why are you using a string at all?
Why not use a number? If your "does it exist" routine returned the integer number of existing emails, then couldn''t you just check that against zero? After all, ExecuteScalar returns a number...


这篇关于vb.net中的重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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