显示特定事件的已加入用户

时间:2017-05-10 22:42:18

标签: c#

我只想问一下如何在我们的系统中显示独特的加入用户,因为我在 Visual Studio 2013 中创建了一个事件管理系统,我想显示有多少人参与了我的确定事件已经。我尝试过代码,但它不起作用,它没有错误,但它没有用。你能帮助我吗?提前谢谢。

这是我的代码:

private void tbx_joined_TextChanged(object sender, EventArgs e)
    {
        String Query = "select count(distinct d.jusername) from dbems.db_join d, dbems.create_event c where d.jeventname = c.eventname";
        MySqlConnection conDataBase = new MySqlConnection(db.mystring());
        MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
        MySqlDataReader myReader;

        try
        {
            conDataBase.Open();
            myReader = cmdDataBase.ExecuteReader();

            while (myReader.Read())
            {
                //"count(distinct d.jusername)"
                string evjoined = myReader.GetInt32(Query).ToString();

                tbx_joined.Text = evjoined;

            }
        }

        catch (Exception)
        {

        }

    }

1 个答案:

答案 0 :(得分:0)

以下是您运行以修复表和数据的脚本:

UsernamePasswordAsync()

以下是您可以使用的新查询:

--USE your db here
USE [Breaz]
GO
/****** Object:  Table [dbo].[dbemEvent]    Script Date: 5/10/2017 4:01:15 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[dbemEvent](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [EventName] [varchar](15) NOT NULL,
 CONSTRAINT [PK_dbemEvent] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[dbemUser]    Script Date: 5/10/2017 4:01:15 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[dbemUser](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Event] [int] NULL,
    [UserName] [varchar](15) NULL,
 CONSTRAINT [PK_dbemUser] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[dbemEvent] ON 

GO
INSERT [dbo].[dbemEvent] ([Id], [EventName]) VALUES (1, N'School')
GO
INSERT [dbo].[dbemEvent] ([Id], [EventName]) VALUES (2, N'Home')
GO
SET IDENTITY_INSERT [dbo].[dbemEvent] OFF
GO
SET IDENTITY_INSERT [dbo].[dbemUser] ON 

GO
INSERT [dbo].[dbemUser] ([Id], [Event], [UserName]) VALUES (1, 1, N'Bob')
GO
INSERT [dbo].[dbemUser] ([Id], [Event], [UserName]) VALUES (2, 1, N'Ken')
GO
INSERT [dbo].[dbemUser] ([Id], [Event], [UserName]) VALUES (3, 2, N'Nick')
GO
INSERT [dbo].[dbemUser] ([Id], [Event], [UserName]) VALUES (4, 2, N'Jack')
GO
SET IDENTITY_INSERT [dbo].[dbemUser] OFF
GO
ALTER TABLE [dbo].[dbemUser]  WITH CHECK ADD  CONSTRAINT [FK_dbemUser_dbemEvent] FOREIGN KEY([Event])
REFERENCES [dbo].[dbemEvent] ([Id])
GO
ALTER TABLE [dbo].[dbemUser] CHECK CONSTRAINT [FK_dbemUser_dbemEvent]
GO