Results 1 to 2 of 2

Thread: I need an ERROR HANDLER

  1. #1

    Thread Starter
    Member bestex's Avatar
    Join Date
    Jan 2010
    Posts
    52

    I need an ERROR HANDLER

    Hi.. all i need is a code to be inserted on these code.. i can save record to my mysql database but theres something wrong because i can save record with the same as the record inserted to my database.. all i want is a code that can detect if the record already exist then show an error and will not save , and a message that will appear that the record has been saved because it doesnt exist.. heres the code
    Code:
    Imports MySql.Data.MySqlClient
    
    
    Public Class Form2
        Dim connection As MySqlConnection
        Dim ra As Integer
    
    
        Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
            connection = New MySqlConnection()
    
            connection.ConnectionString = "server=localhost; user id=root; password=phoenix0931; database=accounts;"
            Try
                connection.Open()
            Catch MyError As MySqlException
                MessageBox.Show("Error in Connection to database; " & MyError.Message)
                Textbox1.Text = ""
                Textbox2.Text = ""
                Textbox1.Focus()
            End Try
            Dim myAdapter As New MySqlDataAdapter
    
            Dim sqlquery = "INSERT INTO users (Username, Password) Values('" & Textbox1.Text & "', '" & Textbox2.Text & "' )"
    
            Dim command As New MySqlCommand
            command.Connection = connection
            command.CommandText = sqlquery
              
    
            myAdapter.InsertCommand = command
            command.ExecuteNonQuery()
    Please lend me a code

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: I need an ERROR HANDLER

    Please do not post multiple threads for the same question (original thread here).

    This thread is now closed.

Posting Permissions

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



Click Here to Expand Forum to Full Width