SQLを使用してクエリを実行する必要がありDataGridView
ますが、に表示されませんDataGridView
。
public chkTime()
{
InitializeComponent();
}
HRTaffDataContext db = new HRTaffDataContext();
SqlConnection Conn;
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da;
DataTable dt = new DataTable();
DataSet ds = new DataSet();
StringBuilder sb = new StringBuilder();
string appConn = ConfigurationManager.ConnectionStrings["connDB"].ConnectionString;
string strDate;
private void chkTime_Load(object sender, EventArgs e)
{
connStr();
return;
}
public void connStr()
{
Conn = new SqlConnection();
if (Conn.State == ConnectionState.Open)
{
Conn.Close();
}
Conn.ConnectionString = appConn;
Conn.Open();
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(appConn);
string sql = "SELECT [filesTA].EmpNo,[Employee].[First Name],[filesTA].ChkDate,[filesTA].ChkIn,[filesTA].ChkOut,[CompanyData].ShortName"
+ " From [WebSP].[dbo].[filesTA] inner join [WebSP].[dbo].[Employee] on [Employee].EmployeeNo=[filesTA].EmpNo INNER JOIN [WebSP].[dbo].[CompanyData] On [CompanyData].Company = [Employee].Company"
+ " WHERE [filesTA].ErrorCode = 0"; // It's work
+ " WHERE [filesTA].ErrorCode = 0 and [filesTA].ChkDate ='" + dateTimePicker.Text.ToString() + "'";
da = new SqlDataAdapter(sql, Conn);
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
dgvShow.DataSource = ds.Tables[0];
}
"WHERE [filesTA].ErrorCode = 0"
正常に動作します。"WHERE [filesTA].ErrorCode = 0 and [filesTA].ChkDate ='" + dateTimePicker.Text.ToString() + "'"
動作しません。
どこに設定する必要がありDateTime
ます。