我有以下代码:
Connection c = new Connection();
string select1 =
@"SELECT
E.employeeNumber AS 'Employee Number',
E.employeePrivateName + ' ' + E.employeeFamilyName AS 'Employee Name',
DATEDIFF (MONTH, E.startWorkingDate, GETDATE()) AS 'Seniority in Month',
M.machineName AS 'Machine Name', J.jobName AS 'Job Name',
COUNT(E.employeeNumber) AS 'Number of Times on Machine in Specif Job',
SUM(Number_Of_Days_During_The_Period) AS 'Total Working Days on Machine in Specif Job',
SUM(Salary_per_Period) AS 'The Salary For working on Machine in Specif Job'
FROM
TblEmployee E
INNER JOIN
AllSchedules A_S on E.employeeNumber = A_S.employeeNumber
INNER JOIN
TblJob J on J.jobNumber = A_S.jobNumber
INNER JOIN
TblMachine M on M.machineNumber = A_S.machineNumber
INNER JOIN
TblPeriod P on P.Number = A_S.periodNumber
WHERE
Month(P.fromDate) = Month(@Month)
GROUP BY
E.employeeNumber, E.employeePrivateName, E.employeeFamilyName,
E.startWorkingDate, M.machineName, J.jobName
ORDER BY
E.employeeFamilyName , E.employeePrivateName";
SqlCommand cmd = new SqlCommand(select1, c.con);
DateTime month = comboBox1.Text;
cmd.Connection = c.con;
cmd.Parameters.AddWithValue("@Month", month);
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd); //c.con is the connection string
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
dataGridView1.ReadOnly = true;
dataGridView1.DataSource = ds.Tables[0];
我想运行查询,但是我需要定义一个日期时间值,以便它成为查询的搜索参数。如何保存 DateTime 变量以使其保存月份数(10 月等)
谢谢