HelloZeno 2018-12-15 08:50 采纳率: 0%
浏览 460

C#使用ajax连接SQL Server时候出现了错误

C#使用ajax连接SQL Server数据库的时候有错误

HTML页面

    <h2>查询学生</h2>
    <input type="text" id="checkInput" placeholder="请输入要查询学生的姓名关键词:" style="width:200px;height:50px" />
    <button type="button" id="checkBtn" style="width:80px;height:55px">查询</button>
    <h2>显示学生</h2>
    <div id="showDiv"></div>

ajax

$(document).ready(function () {
    $("#checkBtn").click(function () {
        var checkInput = $("#checkInput").val();
        var checkInputJson = "{'checkInput':'checkInput'}"

        $.ajax({
            type: "Post",
            url: "Server.aspx/CheckStudInfo",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: checkInputJson,
            success: function (data) {
                $("#showDiv").html(data.d);
            },
            error: function (err) {
                alert(err)
            }
        })
    });
})

服务器页面端出现问题

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Web.Script.Services;
using System.Data;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class Server : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [WebMethod]
        public static List<StudInfo> CheckStudInfo(string checkInput)
        {
            SqlConnection sqlConnection = new SqlConnection();
            string checkSQL = "select * from dbo.StudInfo where StudName like '%" + checkInput + "%'";
            List<StudInfo> list = sqlConnection.Database.SqlQuery<StudInfo>(checkSQL).ToList();
            return list;
        }
    }
}

提示错误

  • 写回答

2条回答 默认 最新

  • threenewbee 2018-12-15 13:36
    关注

    StudInfo,这个类没有找到,可能的原因是
    类型写错了
    缺少using,导致包含StudInfo的命名空间没有导入
    忘记定义StudInfo类型了。

    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度