这个地方一直报错,下面是aspx及cs部分代码段
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="sqlcarss.aspx.cs"
Inherits="sqlcars.MyClass" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Display results of SQL commands on cars db </title>
<style type = "text/css">
.titles {font-style: italic; font-weight: bold;}
</style>
</head>
<body>
<span class ="titles"> Please enter your command: </span>
<form id="myForm" runat="server">
<asp:TextBox ID="command" columns = "80" runat="server" />
<br /><br />
<asp:Button ID="Button1" Text="Submit command" runat="server" />
<br /><br />
<span class ="titles"> Results of your command: </span>
<br /><br />
<asp:Label ID="errors" runat="server" />
<asp:GridView ID="results" runat="server" />
</form>
</body>
</html>
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Odbc;
namespace sqlcars
{
public partial class MyClass : System.Web.UI.Page
{
const string ConnStr = "Driver={MySQL ODBC 8.0 Unicode Driver};"+"Server=localhost;Database=cars;uid=root;pwd=root;options=3";
protected void Page_Load()
{
if (IsPostBack)
{
DoCommand(command.Text);
}
}
protected void DoCommand(string command)
{
OdbcConnection con = new OdbcConnection(ConnStr);
OdbcCommand cmd = new OdbcCommand(command,con);
try
{
con.Open();
OdbcDataReader reader = cmd.ExecuteReader(
CommandBehavior.CloseConnection);
results.DataSource = reader;
results.DataBind();
}
catch (Exception ex)
{
errors.Text = ex.Message;
}
}
}
}
课程作业,一直运行不了,麻烦大神们看一下