Note that there are some explanatory texts on larger screens.

plurals
  1. PORunning SQL Server query using c#
    primarykey
    data
    text
    <p>I have the following code :</p> <pre><code>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]; </code></pre> <p>I want to run the query, however I need to define a datetime value so it would be a search parameter for the query. How do I save the DateTime variable so that it will hold a month number (10 for october, etc.)</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload