亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

帶有dotnet核心的REST API

帶有dotnet核心的REST API

C#
開心每一天1111 2021-05-14 18:21:45
感謝您的觀察,我確實將它們應用了以下代碼,但在測試api之后未返回任何數據。我什至用我的連接字符串代替dbcontext還是一無所有!當閱讀器關閉且閱讀器處于打開狀態時,我收到此錯誤無效的調用FieldCount的嘗試。我在這種情況下已有一周的時間了,任何幫助。FromSql查詢僅返回單個表的實體。我的存儲過程帶有一個參數,并具有4個表的聯接。我已經嘗試使用“ ExecuteSqlCommand”查詢,因為結果是-1。using System.Threading.Tasks;using Microsoft.AspNetCore.Mvc;using ActivaMobileAgent.Persistence;using Microsoft.EntityFrameworkCore;using ActivaMobileAgent.Model;using System.Linq;using System.Collections.Generic;using System.Data.SqlClient;using System;using Dapper;using System.Data;using System.Data.Common; namespace ActivaMobileAgent.Controllers{    [Route("/api/Policy")]    public class PolicyController : Controller    {    private readonly ActivaMobileAgentDbContext context;    public PolicyController(ActivaMobileAgentDbContext context) => this.context = context;    public readonly string connectionString = "Data Source=Localhost;Initial Catalog=HELLOxx;User=sa; Password=Helloxx";    [HttpGet("{id}")]    public async Task<IActionResult> GetPolicy(string id)    {        using (var connection = new SqlConnection("Data Source=Localhost;Initial Catalog=Helios;User=sa; Password=P@ssw0rd"))        {            SqlCommand command = new SqlCommand();            command.Connection = connection;            command.CommandType = System.Data.CommandType.StoredProcedure;            command.CommandText ="dbo.sproc_Contract_Get";            command.Parameters.Add(new SqlParameter("@ContractNumber", SqlDbType.VarChar) { Value = id });            connection.Open();            using (var result = await command.ExecuteReaderAsync())            {                return Json(result);            }        }    }}}
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 140 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號