MYSQL C#get days left查询

时间:2014-01-15 23:03:50

标签: c# mysql sql

Hello Everyone我想获得end_date,格式为2014-01-01

我想使用我的减法方法(有效)和我在end_date中查询什么,所以我可以创建一个if方法来查看他们的订阅是否付费但我不知道如何使查询读取end_date并进行比较到目前为止

这是我目前的代码:

string myConnection = "server=****;user=****;database=***;port=3306;password=***;";
                MySqlConnection myConn = new MySqlConnection(myConnection);
                MySqlCommand SelectCommand = new MySqlCommand("SELECT end_date FROM username = '" + this.username_txt.Text + "'", myConn);
                MySqlDataReader myReader;
                myConn.Open();
                DateTime endDate = get end_date from query here???;
                var DaysLeft = (endDate.Date - now.Date).Days;
                MessageBox.Show(""+ DaysLeft);

1 个答案:

答案 0 :(得分:0)

这样的事情应该让你开始:

string myConnection = "server=****;user=****;database=***;port=3306;password=***;";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand cmd = conn.CreateCommand(); 
SELECT DATEDIFF(NOW(), your_date)
cmd.CommandText = "SELECT DATEDIFF(NOW(), end_date) FROM TABLE WHERE username = '" + this.username_txt.Text + "'";
myConn.Open();
MessageBox.Show(cmd.ExecuteScalar());

TABLE更改为您的表名称。除此之外,我认为它应该有效。