Solved

How to check if the records are exist in table and store it on another table?

Posted on 2009-07-14
5
238 Views
Last Modified: 2012-05-07
I have already a form in VB.net with textbox1.text and buttons from 0 to 9 (as calculator). I would like to have my textbox1.text asking a question three times inside the text itself Enter STD ID , Enter SS ID Enter car #  and check the entering in the database if it is exits or not !
1- If it is exist;
Save him in the table called sign and give him a seat from (1 to 5) if the seat is available and if not let him wait?
con.Open()
 
        MsgBox("A Connection to the Database is now open")
 
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim sql As String
 
        sql = "SELECT * FROM table"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "northwind")
 
.
.
.
.
.
 
 
con.Close()

Open in new window

calc.jpg
0
Comment
Question by:aiman_alnasir
  • 3
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 24848227
I dont understand your question fully but here is an example of how to check if a record already exists in database.


Dim dbcon as new OleDBConnection(connectionstring)
dbcon.open
Dim dbcmd as new OleDBCommand
dbcmd.connection = dbcon
dbcmd.commandtext = "Select Count([Name]) From [Employee] Where [Name]='" & txtName.Text & "'"
Dim Count as Integer = dbcmd.ExecuteScaler()
If Count > 0 Then
   Messagebox.show("This Employee already exists")
End If
dbcmd.dispose
dbcon.dispose

Open in new window

0
 

Author Comment

by:aiman_alnasir
ID: 24848459
This is a good step to start;
Could you please see my code below and fix any errors;
.
.
.
Dim Show1, Show2, Show3 As String
        Show1 = InputBox("Enter STD ID Number: ")
        a = Show1
        Show2 = InputBox("Enter SS ID Number: ")
        b = Show2
        Show3 = InputBox("Enter car Number: ")
        c = Show3

        dbcmd.Connection = con
        dbcmd.CommandText = "Select Count(*) From table Where STD ='" & a & "' and SS = '" & b & "' and car = '" & c & "'"
        ' please note the error message (ExecuteScaler is not a member of System.Data.OleDb.OleDbCommand)    
        Dim Count As Integer = dbcmd.ExecuteScaler()
        If Count > 0 Then
            MessageBox.Show("This Employee already exists")
        End If
        dbcmd.Dispose()
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
ID: 24848657
My typo
Its
dbcmd.ExecuteScalar()
0
 

Author Comment

by:aiman_alnasir
ID: 24856745
Thanks dude,
Now, do you know some code to reserve a space or a seat or a time per day on VB.net? So, whenever the students are available on the database it will allow him to reserve a specific time or seat. For example, if we have 5 seats, 5 students are allow to pick one seat for each and any other students who came after will keep him in the waiting list.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
ID: 24857577
There is no quick code for that functionality. This is what your application will be doing and you need to implement it based on the requirements.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
write xml in vb.net 2 33
VB.NET 2008 - SQL Timeout 9 34
Create a datatable in vb.net dynamically 1 23
VB.NET - Refactor Class per SOLID principles 2 22
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question