如何在vb.net中检查验证 [英] How to check validation in vb.net

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

问题描述

大家好,

对于我的项目,我必须检查确认first_table中是否存在扫描的条形码,如果存在,则可以继续操作(如果不存在,则不允许这样做).

请帮我.这是代码.

Hi Everyone,

For my project I have to check the validation whether the scanned barcode is present in first_table, and, if present then you can proceed if not present then its not allowed.

Please help me for this. Here is the code.

Try
 cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\Mil-Dev2\Documents\Visual Studio 2008\Projects\Project-1st\Project-1st\Mercedez_benz.accdb"

 cn.Open()
 selct = "Select * from Job_card_opening where Sequence_Code=(Select Max(Sequence_Code)as MaxSeqNo From Job_card_opening where Barcode_Number='" & TextBox3.Text & "')"

 dadapt = New OleDbDataAdapter(selct, cn)
 dadapt.Fill(ds, "Job_card_opening")

 If ds.Tables("Job_card_opening").Rows.Count = 0 Then
 ins = "insert into Job_card_opening (UserName,Designation,Barcode_number,IN_Time,Transaction_Completed) values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & Now & "','0')"

 cmd = New OleDbCommand(ins, cn)
 iicount = cmd.ExecuteNonQuery
 MessageBox.Show("Data Inserted")
 TextBox3.Text = ""
 ds.Dispose()
 Else
 Dim selData As String = "Select max(Sequence_Code) from Job_card_opening where Barcode_number = '" & TextBox3.Text & "'"

 Dim dap As OleDbCommand
 dap = New OleDbCommand(selData, cn)
 count = dap.ExecuteScalar
 Dim Selctquery As String = "Select * from Job_card_opening where Sequence_Code = " & count & " and Barcode_Number = '" & TextBox3.Text & "'"

 Dim dsfinddata As New DataSet
 Dim dapselcet As New OleDbDataAdapter
 dapselcet = New OleDbDataAdapter(Selctquery, cn)
 dapselcet.Fill(dsfinddata, "Job_card_opening")
 If IsDBNull(dsfinddata.Tables("Job_card_opening").Rows(0).Item(4)) = False And IsDBNull(dsfinddata.Tables("Job_card_opening").Rows(0).Item(5)) = False Then

 ins = "insert into Job_card_opening (UserName,Designation,Barcode_number,IN_Time,Transaction_Completed) values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & Now & "','0')"

 cmd = New OleDbCommand(ins, cn)
 iicount = cmd.ExecuteNonQuery
 MessageBox.Show("Data Inserted")
 TextBox3.Text = ""
 ds.Dispose()
 ElseIf IsDBNull(dsfinddata.Tables("Job_card_opening").Rows(0).Item(4)) = False And IsDBNull(dsfinddata.Tables("Job_card_opening").Rows(0).Item(5)) = True Then

 mstrscanId = "update Job_card_opening set OUT_Time = '" & Now & "',Transaction_completed = '1' where Barcode_number = '" & TextBox3.Text & "' and OUT_Time is null"

 cmd = New OleDbCommand(mstrscanId, cn)
 count = cmd.ExecuteNonQuery
 MessageBox.Show("Updated Out_time")
 TextBox3.Text = ""
 ds.Dispose()
 End If
 End If
 Catch ex As Exception
 MsgBox(ex.Message)
 End Try
 cn.Close()



预先感谢,
Saumya



Thanks in advance,
Saumya

推荐答案

如果要检查是否存在,则更改为此代码.
如果您使用大于,则表示即使记录多于一个,结果仍然相同

If you are checking wheather it exists then change to this code.
When youu use greater than then it means even if the record are more than one the result with still be the same

If ds.Tables("Job_card_opening").Rows.Count > 0 Then
 ins = "insert into Job_card_opening (UserName,Designation,Barcode_number,IN_Time,Transaction_Completed) values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & Now & "','0')"




请注释您的代码以方便理解




Please comment your code for ease understanding


这篇关于如何在vb.net中检查验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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