我有一个 Windows 应用程序,我在其中使用日期时间选择器进行班次开始和班次结束。我必须将这些时间插入表中。我的代码是:
if (comboBox1.SelectedIndex == 0 || comboBox1.SelectedIndex == 1 || comboBox1.SelectedIndex == 2 || comboBox1.SelectedIndex == 3 || comboBox1.SelectedIndex == 4 || comboBox1.SelectedIndex == 5 || comboBox1.SelectedIndex == 6 || comboBox1.SelectedIndex == 7 || comboBox1.SelectedIndex == 8 || comboBox1.SelectedIndex == 9 || comboBox1.SelectedIndex == 10 || comboBox1.SelectedIndex == 11 || comboBox1.SelectedIndex == 12 || comboBox1.SelectedIndex == 13 || comboBox1.SelectedIndex == 14 || comboBox1.SelectedIndex == 15 || comboBox1.SelectedIndex == 16)
{
string Query = " Insert into [ICPS].[dbo].[Cau reports]( [Name],[Date],[Shift Start],[Shift END ],[Overtime Start],[Overtime End],[Tasks Carried Out],[Normal ],[Overtime],[Normal 1],[Overtime1],[Comments],[Targets_(per hour)]) values ('" + this.textBox1.Text + "','" + this.Date.Text + "', CONVERT(VARCHAR(5),'" + this.SS.Text + "',108), '" + this.SE.Text + "','" + this.OS.Text + "','" + this.OE.Text + "','" + this.comboBox1.SelectedText + "','" + this.NT.Text + "','" + this.OT.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.textBox4.Text + "','" + this.textBox5.Text + "' ) ;";
// string Query = " update [ICPS].[dbo].[Cau reports] set [Normal]='" + this.textBox7.Text + "',[Overtime]='" + this.textBox8.Text + "',[Normal 1]='" + this.textBox2.Text + "',[Overtime1]='" + this.textBox3.Text + "',[comments]='" + this.textBox4.Text + "',[Targets_(per hour)]='" + this.textBox5.Text + "'where [Tasks Carried Out] ='" + this.comboBox1.SelectedText + "'; ";
SqlConnection conDatabase = new SqlConnection(constring);
SqlCommand cmdDataBase = new SqlCommand(Query, conDatabase);
SqlDataReader myReader;
try
{
conDatabase.Open();
myReader = cmdDataBase.ExecuteReader();
MessageBox.Show("Saved");
while (myReader.Read())
{
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
但我的输出是:01/01/1900 16:36(我不需要轮班开始和轮班结束的日期,只需要时间)。任何帮助将不胜感激。请...