Results 1 to 2 of 2

Thread: "Existing record" alert

  1. #1
    bogsai is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0
    Join Date
    Apr 2012
    Posts
    1
    Reputation
    0

    "Existing record" alert

    Hi, i want to know what code to put to pop a message box saying that a record already exist in the database?

    i'm just new to Visual Basic.. i'm using 2008 version by the way and here are the codes that i made

    Private Sub cmdinsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdinsert.Click
    strsql = "insert into client(Name, Address, Bday, Age, City, telnum) values (@field2, @field3, @field4, @field5, @field6, @field7)"
    objcmd = New MySql.Data.MySqlClient.MySqlCommand(strs… objconn)
    With objcmd
    .Parameters.AddWithValue("@field2", txtname.Text)
    .Parameters.AddWithValue("@field3", txtaddr.Text)
    .Parameters.AddWithValue("@field4", txtbday.Text)
    .Parameters.AddWithValue("@field5", txtage.Text)
    .Parameters.AddWithValue("@field6", txtcity.Text)
    .Parameters.AddWithValue("@field7", txtcontact.Text)
    End With
    objcmd.ExecuteNonQuery()
    objcmd.Dispose()
    MsgBox("Client Registered!")

    here is for updating a record

    Private Sub cmdupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupdate.Click

    strsql = "update client set Name=@field2, Address=@field3, Bday=@field4, Age=@field5, City=@field6, telnum=@field7 where cID=@field1"
    objcmd = New MySql.Data.MySqlClient.MySqlCommand(strs… objconn)
    With objcmd
    .Parameters.AddWithValue("@field1", txtid.Text)
    .Parameters.AddWithValue("@field2", txtname.Text)
    .Parameters.AddWithValue("@field3", txtaddr.Text)
    .Parameters.AddWithValue("@field4", txtbday.Text)
    .Parameters.AddWithValue("@field5", txtage.Text)
    .Parameters.AddWithValue("@field6", txtcity.Text)
    .Parameters.AddWithValue("@field7", txtcontact.Text)
    End With

    objcmd.ExecuteNonQuery()
    objcmd.Dispose()
    MsgBox("Info Updated!")

    I want to know what to put in so that every time i enter a new record that matches the same information from the existing one, instead of adding a new row, i can just alert it with a message box saying that "record already exist"..

    i'm using mysql 5.1 database

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,504
    Reputation
    1553
    Query the database first and get a count of the records that match. If that count is not zero then your record is a duplicate.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking