|
-
Oct 3rd, 2010, 05:48 AM
#1
Thread Starter
Member
Record Repeat(HELP)
Hi i build a code that can insert my records to mysql database.. the codes are correct it can save records to the mysql database. Now i want to know is what code will i used that will show an error if the records already exist, so it will not make the same records again. here is my code for my INSERT code for mysql database
Code:
Imports MySql.Data.MySqlClient
Imports System.Data
Public Class Form2
Dim connection As MySqlConnection
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
Dim mydata As MySqlDataReader
mydata = command.ExecuteReader()
Need help please..
-
Oct 3rd, 2010, 07:09 AM
#2
Re: Record Repeat(HELP)
There is no magic. If you want to know whether specific data already exists in the database then you execute a query to retrieve it. If the query returns any data then it exists and if it doesn't then it doesn't. It's just like if you were keeping a list on paper: you look for the value in the list and if you find it then you don't add it again but if you don't find it then you add it. Programming doesn't exist in a vacuum. Programming generally models real-world processes. Whatever you would do in the real world is pretty much what you do in programming.
-
Oct 3rd, 2010, 09:02 AM
#3
Thread Starter
Member
Re: Record Repeat(HELP)
im only a beginner can you give me a code and explain to me so i can understand it well? please if you dont mind?
-
Oct 3rd, 2010, 09:22 AM
#4
Re: Record Repeat(HELP)
There are lots and lots of examples of querying databases using VB.NET. There are many on this forum and many more besides. Look first, ask questions later. You should start with the Database FAQ link in my signature.
Last edited by jmcilhinney; Oct 3rd, 2010 at 09:46 AM.
-
Oct 3rd, 2010, 10:05 AM
#5
Thread Starter
Member
Re: Record Repeat(HELP)
sir please help me with this code. i will review the code you will give so i will understand,,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|