我試圖從文本框中獲取日期時(shí)間,它已經(jīng)準(zhǔn)備好了 MySql 日期時(shí)間的格式。DB中的列也是DateTime格式。但是,當(dāng)我按下按鈕將日期保存在數(shù)據(jù)庫中時(shí),整行將被清空。我在數(shù)據(jù)庫中嘗試了不同的格式和數(shù)據(jù)類型,沒有任何效果private void button4_Click(object sender, EventArgs e){ MySqlConnection conn = DBUtils.GetDBConnection(); conn.Open(); string startzeit = textBoxstartzeit.Text.ToString(); DateTime start = DateTime.Parse(startzeit); string stopzeit = textBoxstopzeit.Text.ToString(); DateTime stop = DateTime.Parse(stopzeit); string pstartzeit = textBoxstopzeit.Text.ToString(); DateTime pstart = DateTime.Parse(pstartzeit); string pstopzeit = textBoxstopzeit.Text.ToString(); DateTime pstop = DateTime.Parse(pstopzeit); MySqlCommand cmdnew = conn.CreateCommand(); cmdnew.CommandType = CommandType.Text; cmdnew.CommandText = "UPDATE arbeitszeiten SET astart = '" + start + "', astop = '" + stop + "', pstart = '" + pstart + "', pstop = '" + pstop + "' WHERE id = '" + dataGridView.CurrentCell.Value + "'"; cmdnew.ExecuteNonQuery(); conn.Close();}private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e){ try { MySqlConnection conn = DBUtils.GetDBConnection(); conn.Open(); MySqlCommand feedstartzeit = conn.CreateCommand(); feedstartzeit.CommandText = "SELECT astart FROM arbeitszeiten WHERE id = '" + dataGridView.CurrentCell.Value + "'"; DateTime start = Convert.ToDateTime(feedstartzeit.ExecuteScalar()); textBoxstartzeit.Text = start.ToString("yyyy-MM-dd HH:mm:ss"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Bitte ID ausw?hlen", MessageBoxButtons.OK, MessageBoxIcon.Error); }}Button4 是上傳新數(shù)據(jù),dataGridView 部分用預(yù)先格式化的日期時(shí)間填充文本框,稍后由 Button4 上傳
- 2 回答
- 0 關(guān)注
- 279 瀏覽
添加回答
舉報(bào)
0/150
提交
取消