Io utilizzo import namespaces, questa e la mia connessione:
<%@ Page Language="C#" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "MySql.Data" %>
<%@ Import Namespace = "MySql.Data.MySqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
MySqlConnection connection = new MySqlConnection();
connection.ConnectionString = "Data Source=localhost; Database=dvd; User ID=root; password=";
connection.Open();
string SQL = "select * from tbdvd";
MySqlCommand cmd = new MySqlCommand(SQL, connection);
MySqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Response.Write("Titolo : " + dr["titolo"] + " - Copertina : " + dr["Copertina"] + "
");
}
}
dr.Close();
connection.Close();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>