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、先说说你自己的想法是什么、

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器