当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - SQL searching daily attributes error

问题描述:

I am trying to build an application which searches all attributes step by step daily and monthly using the between statement. The daily queries run, but monthly dones't run.

The code:

 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();

网友答案:

use

 combine[0]=today2

use first

you may get parameter error to pull data.

String.Format("{0:d/M/yyyy HH:mm:ss}", dt); 
String.Format("{0:d/M/yyyy HH:mm:ss}", dt); 
分享给朋友:
您可能感兴趣的文章:
随机阅读: