gpt4 book ai didi

mysql - SQL查询每日属性报错

转载 作者:行者123 更新时间:2023-11-29 06:36:17 25 4
gpt4 key购买 nike

我正在尝试构建一个应用程序,它使用 between 语句每天和每月逐步搜索所有属性。每日查询运行,但每月不运行。

代码:

 if (libs.conn.con.State == ConnectionState.Closed) libs.conn.baglanti.Open();
string today = "select getdate()";
SqlCommand today1 = new SqlCommand(today, libs.conn.con);
string today2 = today1.ExecuteScalar().ToString();
string[] day = today2.Split(' ');
day[0] += " 00:00:00";
string dayy = (DateTime.Now.Day).ToString();
string month = (DateTime.Now.Month).ToString();
string year = (DateTime.Now.Year).ToString();
string[] combine = new string[] { "1." };
combine[0] += month + ".";
combine[0] += year + " ";
combine[0] += "00:00:00";
string totalmonth = "(SELECT SUM(para) FROM statistics where datee between '"+combine[0]+"' AND '"+today2+"')";
SqlCommand totalmoneymonthlyquery = new SqlCommand(totalmoneymonth, libs.conn.baglanti);
string totalmoneymonthlyresult = totalmoneymonthlyquery.ExecuteScalar().ToString();
textBox7.Text = totalmoneymonthlyresult.ToString();

最佳答案

使用

 combine[0]=today2

先用

拉取数据可能会出现参数错误

String.Format("{0:d/M/yyyy HH:mm:ss}", dt); 
String.Format("{0:d/M/yyyy HH:mm:ss}", dt);

关于mysql - SQL查询每日属性报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24529992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com