Re: Create contact with the MySQL database in the localhost
Posted by: Gabriela Martinez Sanchez
Date: March 03, 2014 12:59PM

Hi Gunnar,

Here's an example of how to make an insert on a table:

Dim myConnectionString = "Database=Test;Data Source=localhost;User Id=username;Password=pass;Port=3307;"
Dim myConnection As New MySqlConnection(myConnectionString)
Dim myInsertQuery As String = "INSERT INTO Orders (id, customerId, amount) Values(1001, 23, 30.66)"
Dim myCommand As New MySqlCommand(myInsertQuery)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()

Notice that the parameters in the connection string has a semicolon as separator for each pair value.
Also for INSERT commands you can use ExecuteNonQuery. Since you won't be receiving any data as a result of the operation.

Everything else looks fine.

You can see more examples at the documentation:

http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqlcommand.html#connector-net-examples-mysqlcommand-executereader

Hope this helps.

Options: ReplyQuote


Subject
Written By
Posted
Re: Create contact with the MySQL database in the localhost
March 03, 2014 12:59PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.