数据绑定:'system.data.datarowview'不包含名为'sports'的属性。 [英] Databinding: 'system.data.datarowview' does not contain a property with the name 'sports'.

查看:106
本文介绍了数据绑定:'system.data.datarowview'不包含名为'sports'的属性。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用asp.net编写了一个聊天室,C#& MS SQL。我有两个下拉菜单用于选择体育,然后另一个用于根据用户在线/总用户排序聊天室。



当我选择所有运动(默认值)和在线用户,查询工作正常。

但是当我选择所有运动(默认值)和总用户数时,查询会出现一些错误。



I have coded a chatroom using asp.net, C# & MS SQL. I have two Dropdowns for selecting Sports and then another for Sorting the chatrooms based on Users online/total users.

When I select "All sports" (default value) and "Users online", the query works fine.
But when I select "All sports" (default value) and "total users", the query gives some error.

"SELECT roo.[Sports] As Sport, roo.[Name] AS ChatRoomName, COUNT(DISTINCT liu.[LoggedInUserID]) AS OnlineUsers, COUNT(DISTINCT chu.ChatUserLogId) AS TotalUsers FROM Room AS roo LEFT JOIN LoggedInUser AS liu ON roo.RoomID = liu.RoomID LEFT JOIN ChatUserLog AS chu ON roo.RoomID = chu.RoomID AND chu.LoggedInTime >= DATEADD(DAY,-30,GETDATE()) GROUP BY roo.[Sports], roo.[Name]";





结果应该是这样的





The results should be like this

                   Chatroom Name      Online users              Total Users
Football 
              Best football player ever?    0                       5671
              Messi or Ronaldo?             5                       346
              Who'll win EURO this year?    0                       134
Swimming 
              Best ever Swimmer?            0                       3343
              Phelps or Spitz?              0                       1056
              Lochte or Phelps for gold?    0                       45
              
Tennis
              Serena or Steffi graf?        0                       432
              Federer or Djokovic?          0                       298
              Best server ever?             0                       43





我的结果没有得到正确的排序,以及有在线用户的运动也会出现两次。





My results are not getting sorted properly as well as the sports having online users are shown twice too.

CREATE TABLE [dbo].[ChatUserLog] (
    [ChatUserLogId] BIGINT   IDENTITY (1, 1) NOT NULL,
    [MId]           INT      NOT NULL,
    [RoomId]        INT      NOT NULL,
    [LoggedInTime]  DATETIME DEFAULT (getdate()) NOT NULL,
    [LogOutTime]    DATETIME DEFAULT (getdate()) NULL,
    PRIMARY KEY CLUSTERED ([ChatUserLogId] ASC)
);
 
CREATE TABLE [dbo].[LoggedInUser] (
    [LoggedInUserID] INT           IDENTITY (1, 1) NOT NULL,
    [MId]            INT           NOT NULL,
    [RoomID]         INT           NOT NULL,
    [NickName]       VARCHAR (50)  NOT NULL,
    [Icon]           VARCHAR (MAX) NOT NULL,
    CONSTRAINT [PK_LoggedInUser] PRIMARY KEY CLUSTERED ([LoggedInUserID] ASC)
);







CREATE TABLE [dbo].[Message] (
    [MessageID] INT           IDENTITY (1, 1) NOT NULL,
    [RoomID]    INT           NOT NULL,
    [MId]       INT           NOT NULL,
    [ToUserID]  INT           NULL,
    [Text]      VARCHAR (MAX) NOT NULL,
    [TimeStamp] DATETIME      DEFAULT (getdate()) NOT NULL,
    [Color]     VARCHAR (50)  NULL,
    [NickName]  VARCHAR (50)  NOT NULL,
    [Icon]      VARCHAR (MAX) NOT NULL,
    PRIMARY KEY CLUSTERED ([MessageID] ASC)
);
 
CREATE TABLE [dbo].[Room] (
    [RoomID]        INT           IDENTITY (6666, 1) NOT NULL,
    [Name]          VARCHAR (100) NOT NULL,
    [Sports]        VARCHAR (50)  NOT NULL,
    [CreatedDate]   DATETIME      DEFAULT (getdate()) NOT NULL,
    [CreatedBy]     VARCHAR (50)  NOT NULL,
    [CreatedUserID] INT           NOT NULL,
    PRIMARY KEY CLUSTERED ([RoomID] ASC)
);





提前致谢,祝你有个美好的一天。



我的尝试:



我正在尝试





Thanks in advance and have a nice day ahead.

What I have tried:

I am trying

"SELECT roo.[Sports] As Sport, roo.[Name] AS ChatRoomName, COUNT(DISTINCT liu.[LoggedInUserID]) AS OnlineUsers, COUNT(DISTINCT chu.ChatUserLogId) AS TotalUsers FROM Room AS roo LEFT JOIN LoggedInUser AS liu ON roo.RoomID = liu.RoomID LEFT JOIN ChatUserLog AS chu ON roo.RoomID = chu.RoomID AND chu.LoggedInTime >= DATEADD(DAY,-30,GETDATE()) GROUP BY roo.[Sports], roo.[Name]";

推荐答案

从错误看,它看起来像你是尝试从datarowview访问应用程序中的值,其中存储了共享查询的结果但键错了。



From the error, it looks like you are trying to access a value in the application from datarowview where the result of the shared query is stored but with wrong key.

SELECT roo.[Sports] As Sport,...
...

]

列是运动,但看起来你正试图通过运动进行访问,这可能会导致错误。

查看相关代码并尝试从体育中删除最后一个s



希望,它有帮助:)

如果我遗漏了明显的东西,请告诉我。

]
The column is Sport but looks like you are trying to access with Sports and that's probably causing the error.
Look at the relevant code and try removing the last "s" from "Sports".

Hope, it helps :)
Please let me know if I am missing something obvious here.


这篇关于数据绑定:'system.data.datarowview'不包含名为'sports'的属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆