首页 > 解决方案 > .Net Core 3.1 和 Postgresql 插入和更新查询未执行,但选择查询运行成功

问题描述

大家好,当我请求 postgresql 运行任何插入数据并在 refcursor 中选择数据的函数时,我正在使用没有实体框架的 Postgresql 和 .Net Core Api 3.1。

在此函数中,选择查询运行良好,但数据未插入数据库表中。

相同的功能在 Asp .Net Web Forms 中正常工作,但在 Asp .Net Core 中不能正常工作。

我是 postgresql 的新手

public string Save_Siteinpection_update(SiteInspection model)
{
    string result = ResponseStatus.FAILED;
    try
    {
        var conn = SqlHelper.NpSqlConnection();
        conn.Open();

        DataSet ds = new DataSet();

        var tran = conn.BeginTransaction();
        var command1 = new NpgsqlCommand("mob_sp_siteinspection_update3", conn);

        command1.Parameters.AddWithValue("para_document_sno", Convert.ToInt64(model.docsrno));
        command1.Parameters.AddWithValue("para_dig_code", Convert.ToInt32(model.dig_code));
        command1.Parameters.AddWithValue("para_srocode", Convert.ToInt32(model.srocode));
        command1.Parameters.AddWithValue("para_site_visited", model.site_visited);
        command1.Parameters.AddWithValue("para_visit_satisfy", model.visit_satisfy);
        command1.Parameters.AddWithValue("para_contact_person", model.contact_person);
        command1.Parameters.AddWithValue("para_longitude_prop", model.longitude_prop);
        command1.Parameters.AddWithValue("para_latitude_prop", model.latitude_prop);
        command1.Parameters.AddWithValue("para_adrees_prop", model.adrees_prop);
        command1.Parameters.AddWithValue("para_city_prop", model.city_prop);
        command1.Parameters.AddWithValue("para_zip", model.zip);
        command1.Parameters.AddWithValue("para_country_prop", model.country_prop);
        command1.Parameters.AddWithValue("para_state_prop", model.state_prop);
        command1.Parameters.AddWithValue("para_img1", model.img1);
        command1.Parameters.AddWithValue("para_img2", model.img2);
        command1.Parameters.AddWithValue("para_img3", model.img3);
        command1.Parameters.AddWithValue("para_img4", model.img4);
        command1.Parameters.AddWithValue("para_remark", model.remark);
        command1.CommandType = CommandType.StoredProcedure;

        NpgsqlDataAdapter da = new NpgsqlDataAdapter(command1);
        da.Fill(ds);

        string np_no = ds.Tables[0].Rows[0]["mob_sp_siteinspection_update3"].ToString();

        command1.CommandText = "fetch all in \"" + np_no + "\"";
        command1.CommandType = CommandType.Text;

        NpgsqlDataReader sdr = command1.ExecuteReader();
        while (sdr.Read())
        {
            result = Convert.ToString(sdr[0].ToString());
        }
        sdr.Close();
        conn.Close();
    }
    catch (Exception ex)
    {

    }
    return result;
}

标签: postgresqlapiasp.net-core

解决方案


推荐阅读