weixin_43822562 2019-12-25 09:00 采纳率: 50%
浏览 322

请大神帮我看看代码哪里错了

图片说明

这个地方一直报错,下面是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;
            }
        }
    }
}

课程作业,一直运行不了,麻烦大神们看一下

  • 写回答

2条回答 默认 最新

  • weixin_43169505 2019-12-25 09:46
    关注

    建议把问题描述清楚些:
    1、BS架构的还是CS架构的?
    2、实时性的要求如何?比如聊天室内需要看到有哪些人吗?
    3、先说说你自己的想法是什么、

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!