没有日期字段的第二个查询(注释的查询)可以正常工作。
Try
con.Open()
ds.Tables.Add(dt)
Dim Combocolumn As New DataGridViewComboBoxColumn()
Dim frm_date As Date
Combocolumn.HeaderText = "Overtime Hrs"
Combocolumn.Name = "ovr_hrs"
row = New ArrayList()
row.Add("4")
row.Add("3.5")
row.Add("3")
row.Add("2.5")
row.Add("2")
row.Add("1.5")
row.Add("1")
row.Add("0.5")
row.Add("0")
frm_date = dtp4.Value.Date ' dtp is a DateTimePicker
da = New OleDbDataAdapter("Select a.emp_id as Employee_Id, b.emp_name as Employee_Name from awipl_ea a, awipl_emp_info b WHERE a.emp_id = b.emp_id AND a.sft = " & cb18.SelectedIndex + 1 & " AND a.dept = " & txt27.Text & " AND a.dt = '" & frm_date.Date & "'", con)
'da = New OleDbDataAdapter("Select a.emp_id as Employee_Id, b.emp_name as Employee_Name from awipl_ea a, awipl_emp_info b WHERE a.emp_id = b.emp_id AND a.sft = " & cb18.SelectedIndex + 1 & " AND a.dept = " & txt27.Text & " ", con)
cmd = New OleDb.OleDbCommand(sqlStr, con)
da.Fill(dt)
dgv1.DataSource = dt.DefaultView
Combocolumn.Items.AddRange(row.ToArray())
dgv1.Columns.Add(Combocolumn)
dgv1.Columns(1).ReadOnly = True
dgv1.Columns(2).ReadOnly = False
dgv1.Columns(0).ReadOnly = True
Catch ex As Exception
MsgBox(ex.Message)
Finally
con.Close()
End Try
答案 0 :(得分:0)
要在查询的Where子句中使用日期,您需要使用井号[{1}}。
像这样:
#