首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >C#查询结果似乎已缓存-强制重新加载已修改的数据

C#查询结果似乎已缓存-强制重新加载已修改的数据
EN

Stack Overflow用户
提问于 2017-01-07 00:12:03
回答 0查看 461关注 0票数 0

我有一个两页的网站-一个页面显示文档列表,另一个编辑该文档的属性。

现在,如果我编辑文档的属性,保存所做的更改,我可以看到数据库中的数据已更改。但是当我重新加载文档列表时,该列表包含了旧数据。点击刷新,将显示修改后的数据。

如果我跟踪这些更改,它看起来确实像是返回了旧数据。

我尝试过在URL中传递刻度数,让IE加载一个新版本--但它仍然显示旧版本的数据。即使我刷新了页面,它也发生了变化--显示相同的文档详细信息,并显示旧版本的数据,再次刷新,它就会更新。

我已经检查了底层数据库中的数据是否正在更改。

所以接下下面的电话

代码语言:javascript
运行
复制
          using (nhs_patient_document_s documents = new nhs_patient_document_s(Properties.Settings.Default.DataConnectionEDM))
            {
                List<nhs_patient_document> found = documents.Select<nhs_patient_document>("nhs_patdoc_patientid", String.IsNullOrEmpty(criteria) ? String.Empty : criteria);

                output = JsonConvert.SerializeObject(found);
            }

最终,这是执行查询的代码

代码语言:javascript
运行
复制
    public List<T> Select<T>(String Field, String Value)
    {
        List<T> results = null;
        String sql = String.Empty;

        try
        {
            sql = (String.Format("select * From {0} Where {1} = '{2}'", TableName, Field, Value.Replace("'", "''")));
            results = Execute<T>(sql, CommandType.Text);
        }
        catch (System.Exception e)
        {
             throw e;
        }
        finally
        {
            sql = String.Empty;
        }

        return results;
    }

上面调用的execute函数如下;

代码语言:javascript
运行
复制
    protected List<T> Execute<T>(String CommandString, CommandType CommandType)
    {
        DataSet dataSet             = null;
        SqlConnection connection    = null;
        SqlCommand command          = null;
        SqlDataAdapter dataAdapter  = null;

        List<T> results             = null;

        try
        {
            connection          = new SqlConnection(connectionString);

            command             = new SqlCommand(CommandString, connection);
            command.CommandType = CommandType;
            command.CommandTimeout = 0;

            if (connection.State != ConnectionState.Open) connection.Open();

            dataSet     = new DataSet();
            dataAdapter = new SqlDataAdapter(command);
            dataAdapter.Fill(dataSet);

            results     = ExtractData<T>(dataSet);
        }
        catch ( System.Exception e)
        {
            throw e;
        }

        return results;

    }

任何想法,我可以强制它从服务器获取新数据。

PS感谢其他框架的建议,但我只有很短的时间来写这篇文章,没有时间去学习它们。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41509626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档