tpra21
Active member
- Joined
- Oct 21, 2006
- Messages
- 26
- Programming Experience
- 1-3
The code below will add a record to my Reminders table. The DueDate is a date type in mm/dd/yyyy format. When I run this and enter an invalid date in the txtDate textbox, it throws and catches a format exception and displays a message box.
The problem is after the user clicks ok on the error message box, enters another date, and clicks the button that the below code is in, the program throws the following exception:
Parameter ? _ 1 has no default value.
It seems like the error message box is clearing my dataset or something. I don't understand why the DueDate parameter would be empty if the user types in a valid date after getting the error.
Any help would be great.
Thanks, Adam
The problem is after the user clicks ok on the error message box, enters another date, and clicks the button that the below code is in, the program throws the following exception:
Parameter ? _ 1 has no default value.
It seems like the error message box is clearing my dataset or something. I don't understand why the DueDate parameter would be empty if the user types in a valid date after getting the error.
Any help would be great.
Thanks, Adam
VB.NET:
[SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].OleDbInsertCommand1.CommandText = "INSERT INTO Reminders(DueDate, Message) VALUES (?, ?)"[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].OleDbInsertCommand1.Connection = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].OleDbConnection2[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].OleDbInsertCommand1.Parameters.Add("@DueDate", System.Data.OleDb.OleDbType.DBDate, 0, "DueDate").Value = [/SIZE][SIZE=2][COLOR=#0000ff]CDate[/COLOR][/SIZE][SIZE=2](txtDate.Text)[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].OleDbInsertCommand1.Parameters.Add("@Message", System.Data.OleDb.OleDbType.VarWChar, 255, "Message").Value = txtMessage.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[SIZE=2]OleDbConnection2.Open()[/SIZE]
[SIZE=2]OleDbInsertCommand1.ExecuteNonQuery()[/SIZE]
[SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception[/SIZE]
[SIZE=2]MessageBox.Show(ex.Message)[/SIZE]
[SIZE=2][COLOR=#0000ff]Finally[/COLOR][/SIZE]
[SIZE=2]OleDbConnection2.Close()[/SIZE]
[SIZE=2]MessageBox.Show("The Record Has Been Added", "Reminder Added", MessageBoxButtons.OK, MessageBoxIcon.Information)[/SIZE]
[SIZE=2]Reminders1.Reminders.Clear()[/SIZE]
[SIZE=2]OleDbDataAdapter1.Fill(Reminders1)[/SIZE]
[SIZE=2]btnAdd.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2]btnUpdate.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2]btnDelete.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2]ComboBox1.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2]btnConfirm.Visible = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2]btnConfirm.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2]btnConfirm.Text = ""[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] InvalidCastException [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception[/SIZE]
[SIZE=2]MessageBox.Show("Invalid format. Please enter in mm/dd/yyyy format", _[/SIZE]
[SIZE=2]"Invalid Format", _[/SIZE]
[SIZE=2]MessageBoxButtons.OK, MessageBoxIcon.Exclamation)[/SIZE]
[SIZE=2]Reminders1.Reminders.Clear()[/SIZE]
[SIZE=2]OleDbDataAdapter1.Fill(Reminders1)[/SIZE]
[SIZE=2]txtDate.Text = ""[/SIZE]
[SIZE=2]txtDate.Focus()[/SIZE]
[SIZE=2][COLOR=#0000ff]Finally[/COLOR][/SIZE]
[SIZE=2]ComboBox1.Focus()[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]