473,388 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

VB Check if record exist

Hi all,

i have this problem;

- i want to check if the serial number is exist inside the database, and if its exist, i want to check one of the column name called "FLAG" if its equal to 1 or 0. can someone suggest me on how can i do the code?

FYI, my current code is ;

Expand|Select|Wrap|Line Numbers
  1. Private Sub SRN_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles SRN.KeyUp
  2.         If e.KeyCode = Keys.Enter Then
  3.             Dim myconnect As New SqlClient.SqlConnection
  4.             myconnect.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\User\My Documents\ETdb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
  5.             Dim mycommand As SqlClient.SqlCommand = New SqlClient.SqlCommand()
  6.             mycommand.Connection = myconnect
  7.  
  8.             mycommand.CommandText = "INSERT INTO T3 (SRN, SESSION, EVENT_NAME, SYSTIME, SYSDATE, FLAG) VALUES (' " & Replace(SRN.Text, vbNewLine, "") & "' ,'" & SESSION.Text & " ',' " & EVENT_NAME.Text & "','" & SYSTIME.Text & " ','" & SYSDATE.Text & "','" & "1" & "')"
  9.  
  10.             myconnect.Open()
  11.             mycommand.ExecuteNonQuery()
  12.             myconnect.Close()
  13.             SRN.Text = ""
  14.         End If
  15.     End Sub
----

There is nothing wrong with this code, i manage to add new record, but i need your help to do one more function which is, if the record is exist then i no need to add new record but only to change the value of the "FLAG" from 1 -> 0 or the other way around. i really need your help. thank you.
Jan 15 '15 #1
1 2984
Frinavale
9,735 Expert Mod 8TB
For a basic overview, please check out the How to Use a DataBase in Your Program article.

_Frinny
Jan 15 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Lin Ma | last post by:
Greetings, Is it possbile to check a file exist without using Server.CreateObject("Scripting.FileSystemObject") in asp page?? The reason is our hosting company turn that function off for...
1
by: philipdm | last post by:
Ok, I have a data warehouse that I am pulling records from using Oracle SQL. I have a select statement that looks like the one below. Now what I need to do is where the astrics are **** create a...
7
by: andylcx | last post by:
Hi all: The c++ language can check whether the file exist or not. I am wondering how c language does this job? Thanks a lot! Andy
1
by: kannabiran | last post by:
Hi 2 all.. Im using vb.net as front end and oracle as back end,can you help me to find the record is exists or not on before inserting the record,if exists means i need a msgbox as this...
1
by: mamun | last post by:
Hi All, I am doing it for the first time in C# (using Visual Studio 2005), First I need to check if data exists in a table for a variable. If so then run the second query and display the...
9
reginaldmerritt
by: reginaldmerritt | last post by:
I have a table which uses two primary keys. One is a canidate code the other is a course\programme code. I have a fom with these two fields but automaticaly picks the candidates code. Therefore...
28
TheSmileyCoder
by: TheSmileyCoder | last post by:
I need to update a record in a table if the record allready exists, but if it does not exist, I need to insert the record. Is there a 1-step SQL way of doing this? I can easily perform the 2...
1
by: Adya | last post by:
Hi all, I have a list of files starting with a 4 digit code as below, 1) MI01_xxxx_xxxxx.pdf 2) MI01_xxx.pdf 3) MI01_xxxxx.pdf 4) MI03_xxxxx_xxxxx_xxxx.pdf 5) MI04_xxxxxxx_xxxx.pdf 6)...
3
Jerry Maiapu
by: Jerry Maiapu | last post by:
Hello every one. I have spend an humble time - 4-5 months far away from city and could not get into this forum. ( no internet) I am now back into programming trying to create a small...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.