Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

VB
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()


Thanks in advance,
Saumya
Posted
Updated 11-Jan-11 21:33pm
v3
Comments
Baji Jabbar 12-Jan-11 1:21am    
Can u please provide comments in the code in order to get a better understanding. On the first look there I noticed some logical mistake, it might be my mistake , your comments on the code will give a good understanding of your logic
Dalek Dave 12-Jan-11 3:33am    
Edited for Grammar.

1 solution

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

SQL
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
 
Share this answer
 
v2
Comments
Dalek Dave 12-Jan-11 3:34am    
Good Answer, but I edited slightly for grammar

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900