首页 > 解决方案 > 使用 mysql 和 c# 编程语言搜索存在的时间

问题描述

我想要的是搜索给定的小时是否已经存在于我正在使用 MySQL 数据库和 c# 编程语言 win.form 的数据库中。

string connection = "datasource=localhost;username=root;password=root";
        MySqlConnection conDatabase = new MySqlConnection(connection);
        DataSet ds = new DataSet();
        MySqlCommand cmdDatabase = new MySqlCommand("SELECT * FROM 
parking_reservation.bookedslots WHERE entryHour = 
'"+this.EntryHour.Value+"'", conDatabase);

        try
        {
            MySqlDataAdapter sda = new MySqlDataAdapter(cmdDatabase);

            sda.Fill(ds);
            int i = ds.Tables[0].Rows.Count;
            if (i > 0)
            {
                MessageBox.Show("Already Booked");
                ds.Clear();
            }
            else
            {
                MessageBox.Show("Booked Successfuly");
            }

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

标签: c#mysqldatabasewinforms

解决方案


推荐阅读