检查文本框中的插入值是否在SQL Server数据库中可用 [英] check the inserted value in text Box is available in sql server database or not

查看:84
本文介绍了检查文本框中的插入值是否在SQL Server数据库中可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
这是我的代码

Hello,
this is my code

con = New SqlConnection("Data Source=LOCALhost;Initial Catalog=InwardOutwardSystem;Integrated Security=True")
        con.Open()
        Dim T As String
        Dim x As String
        x = "select LoginId from UserMaster"
        
        If CBFrom.Text = x Then
            T = "insert into TransactionMaster(TransactionType)values=('Inward') "
        Else
            T = "insert into TransactionMaster(TransactionType)values('OutsideInward')"
        End If
        cmd = New SqlCommand(T, con)
        DR = cmd.ExecuteReader(CommandBehavior.CloseConnection)


在这个
UserMaster是该LoginId字段中的一个表,应用名称已重新注册

并且我想检查"CBFrom.Text"是否是我的应用程序,来自TextBox名称.
如果我要检查TextBox值是否与UserMaster Table值匹配.
如果匹配,则执行第一条语句
否则执行else语句.
但是bt不起作用.
请告诉我这是什么问题.


In this
UserMaster is a Table in that LoginId field the employes name is resigter already

and i want to check that "CBFrom.Text" this is my application From TextBox name.
in if condition i m check the TextBox value is match with the UserMaster Table value or not.
if it will be matched then execute the 1st statement
otherwise execute the else statement.
But bt not work.
plz tell me what is wrong in this.

推荐答案

尝试

try

If CBFrom.Text = x Then
  T = "insert into TransactionMaster (TransactionType) values ('Inward')"
Else
  T = "insert into TransactionMaster (TransactionType) values('OutsideInward')"
End If



由于这是插入查询,因此可以调用SqlCommand.ExecuteNonQuery方法.



since this is insert queary you can call SqlCommand.ExecuteNonQuery method.

cmd.ExecuteNonQuery(CommandBehavior.CloseConnection)


这篇关于检查文本框中的插入值是否在SQL Server数据库中可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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