ASP.NET / MySQL

Insert Data into a MySQL Table.

 

This is a very rough but working example of inserting data into a MySQL table from ASP.NET. It was adapted from an example of inserting into a MS SQL table. As presented, it actually contains left over code from the old example that is unused, but the table insert command works, which is the important part.

 

Default.aspx

 

Default.aspx.vb

 

How it works: Text boxes are created that correspond to columns in a MySQL table. A button is created with a Protected Sub attached to it. When clicked, the text from each box is inserted into the corresponding column in the MySQL TESTTABLE. 

One important line of code is located in the sqldatasource:

InsertCommand="INSERT INTO TESTTABLE (CustID, CustNAME, ADD1, ADD2, CITY, ZIP) VALUES (?CustID, ?CustName, ?ADD1, ?ADD2, ?CITY, ?ZIP)" 

The rest of the SQL commands in the sqldatasource are actually left over from an old example and are unused.

Note also that this is an example that has been slightly modified for what I needed it to do, so the tab order and the size of the textboxes may not be optimal for this example, but this is cosmetic and shouldn't affect how it actually works.

 

Tags:  asp.net 3.5, Visual Basic, VB, MySQL 5.1, MySQL .net connector