value of type 'DBNull'can not be converted into 'Date'
Dim enddate As Date If end_dateDateTimePicker1.Checked Then enddate = end_DateTimePicker1.Value.Date Else endddate = System.DBNull.Value End If Dim command As OleDbCommand str = "insert into Construction_Progress_Table(end_date) values('" & endddate & "'" command = New OleDbCommand(str, PO_con) command.ExecuteNonQuery()
Using command As New OleDbCommand("INSERT INTO Construction_Progress_Table (end_date) VALUES (?)", PO_con) If end_dateDateTimePicker1.Checked Then command.Parameters.AddWithValue("@EndDate", end_DateTimePicker1.Value.Date) Else command.Parameters.AddWithValue("@EndDate", System.DBNull.Value) End If command.ExecuteNonQuery() End Using
Using command As New OleDbCommand("INSERT INTO Construction_Progress_Table (col1, col2, col3, ...) VALUES (?, ?, ?, ...)", PO_con) If end_dateDateTimePicker1.Checked Then command.Parameters.AddWithValue("@EndDate1", end_DateTimePicker1.Value.Date) Else command.Parameters.AddWithValue("@EndDate1", System.DBNull.Value) End If If end_dateDateTimePicker2.Checked Then command.Parameters.AddWithValue("@EndDate2", end_DateTimePicker2.Value.Date) Else command.Parameters.AddWithValue("@EndDate2", System.DBNull.Value) End If If end_dateDateTimePicker3.Checked Then command.Parameters.AddWithValue("@EndDate3", end_DateTimePicker3.Value.Date) Else command.Parameters.AddWithValue("@EndDate3", System.DBNull.Value) End If ... command.ExecuteNonQuery() End Using
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)