This is part of the LAMA – Best of all worlds tutorial
LAMA Tutorial Home Page
MySql Test Site with Visual Web Developer 2005
1.) Lets open up VWD, and create a new website called mysql-test-site
2.) Add the Mysql Connector/Net to the references.
Right click on the website name in Solution explorer, and choose Add Reference.
Select the MySql.Data from the list, and choose OK.
3.) Add a Data Grid View to the page.
In the Toolbox under Data, Select Grid View and drag it out onto the blank page.
4.) Your Code behind file should have the following code in it:
Imports System.Data
Imports MySql.Data.MySqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) HandlesMe.Load
‘The MySql Connection String: replace IP address with the IP address of your LAMA server
Dim Conn As NewMySqlConnection(“server=192.168.1.37,database=testsite,Uid=aspnet,Pwd=aspnetpassword”)
Dim sSql As String = _
“Select * from phonebook”
Dim DA As New MySqlDataAdapter(sSql, Conn)
Dim DT As New DataTable
DA.Fill(DT)
Me.GridView1.DataSource = DT ‘set the datagrid to the datatable
Me.DataBind()
End Sub
End Class
5.) Run the project in VWD to make sure it works. You should see a datagrid with our test data in it.
If you see John Doe, then its time to copy your project into your asp_net share and setup a test site for it.
Follow the instructions in the tutorial for copying and setting up the Asp.net site.
VB.net users: Make sure to precompile your sites before copying them to the LAMA server.