Delete Date

  • Thread starter Thread starter BD
  • Start date Start date
B

BD

Developing C# windows forms application in Visual Studio 2005 to
access SQL Server 2005 on remote server. On one form I have a textbox
to enter short date. If I delete the date in the textbox, it does not
validate and therefore will not update the server. I know I should
enter null value but have been unsuccessful.
 
BD said:
Developing C# windows forms application in Visual Studio 2005 to
access SQL Server 2005 on remote server. On one form I have a textbox
to enter short date. If I delete the date in the textbox, it does not
validate and therefore will not update the server. I know I should
enter null value but have been unsuccessful.
Can you post your insert statement?
 
Can you post your insert statement?

I do not have an insert statement at the present. I am migrating from
MSACCESS to C# and learning a new language, so therefore, having a
problem coding the statement. I can tell you, the column in SQL is
DATETIME and on the application I am only interested in short date not
time. Thought about using DateTimePicker control but found I could
not blank out or Null the textbox. Also found I could not delete the
value in the textbox.
 
BD said:
I do not have an insert statement at the present. I am migrating from
MSACCESS to C# and learning a new language, so therefore, having a
problem coding the statement. I can tell you, the column in SQL is
DATETIME and on the application I am only interested in short date not
time. Thought about using DateTimePicker control but found I could
not blank out or Null the textbox. Also found I could not delete the
value in the textbox.
Use System.DBNull.Value to insert null values.

i.e
if(txtDate != null) {
// Do Stuff
} else {
// Insert System.DbNull.Value
}
 
Use System.DBNull.Value to insert null values.

i.e
if(txtDate != null) {
// Do Stuff
} else {
// Insert System.DbNull.Value
}- Hide quoted text -

- Show quoted text -

How do I handle the validation process? Would I need to insert this
into the validating event?
 
Developing C# windows forms application in Visual Studio 2005 to
access SQL Server 2005 on remote server. On one form I have a textbox
to enter short date. If I delete the date in the textbox, it does not
validate and therefore will not update the server. I know I should
enter null value but have been unsuccessful.

Personally I'd try to avoid this problem by using a datepicker
control, that allows null values to be specified. You can then in your
code react as appropriate based on whether the user provided a date or
a null, without needing to validate anything
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top