简体   繁体   English

我的SQL + C#古怪问题

[英]My SQL + C# Weird Issue

I'm getting very weird error on the page on every other refresh but NOT every time. 每次其他刷新时,页面上都会出现非常奇怪的错误,但并非每次都显示。

I have a simple page printing out the data as follow: 我有一个简单的页面,将数据打印如下:

Backend(aspx.cs) 后端(aspx.cs)

string sql="Select * from content_mgr_multiple where category = '1' limit 0, 1";    
DataView dv = DBAccess.GetListView(sql);
this.ResultList.DataSource = dv;
this.ResultList.DataBind();

Frontend(aspx) 前端(aspx)

<asp:Repeater ID="ResultList" runat="server">
<ItemTemplate>
     <%#  Eval("content") %>
</ItemTemplate>
</asp:Repeater>

The code work as simple as above but it is showing the following error for every other refresh. 该代码的工作原理如上所述,但每次其他刷新都会显示以下错误。 DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'content'. DataBinding:'System.Data.DataRowView'不包含名称为'content'的属性。

Let's say I refresh the page 6 times. 假设我将页面刷新了6次。 2nd,4th and 6th time are fine but 1st,3rd and 5th time are showing above error. 第二,第四和第六次很好,但是第一,第三和第五次显示上述错误。

I tried to troubleshoot as follow. 我尝试按照以下方法进行故障排除。 I put codes to print out the column names in that DataSource. 我将代码打印出该数据源中的列名。

string sql="Select * from content_mgr_multiple where category = '1' limit 0, 1";    
DataView dv = DBAccess.GetListView(sql);
        foreach (DataColumn dr in dv.Table.Columns)
        {
            Response.Write(dr.ColumnName + "<BR>");
        }
this.ResultList.DataSource = dv;
this.ResultList.DataBind();

On 2nd,4th and 6th time refresh, the column names are printed out in English. 在第二,第四和第六次刷新时,列名以英文打印。

id
category
title
titleCh
content
contentCh

On 1st,3rd and 5th time refresh, the column names are printed out in Chinese. 在第一次,第三次和第五次刷新时,列名称以中文打印。

楤
捡瑥杯特
瑩瑬�
瑩瑬敃�
捯湴敮�
捯湴敮瑃�

I have been fighting this for a while and please help. 我已经为此战斗了一段时间,请帮忙。 Thanks. 谢谢。

Thank you guys very much for your concern. 非常感谢你们的关心。 Finally, I found what was causing it. 终于,我找到了造成它的原因。 As eggyal pointed out, it made me realize that something was wrong with the database. 正如eggyal所指出的,这使我意识到数据库出了点问题。

I have content_mgr category table which is holding Chinese titles too. 我的content_mgr类别表也包含中文标题。 In that category table, the Chinese filed was created as "ucs2_general_ci". 在该类别表中,中文字段被创建为“ ucs2_general_ci”。 As soon as I changed it to "utf8_general_ci", the problem is solved. 我将其更改为“ utf8_general_ci”后,问题就解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM