Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database not reading value from DateTimPicker 1

Status
Not open for further replies.

artyk

Programmer
Apr 5, 2006
163
0
0
US
I have 5 DateTimePicker controls on my form, each containing the date and time. Their Value properties are all bound to the appropriate fields in the database. However when I execute the EndEdit() statement for my BindingSource it gives an error saying that the column bound to the first DateTimePicker doesn't allow nulls. None of the other controls seem to have a problem, only the DateTimePickers. Also, I have set the columns in the database to allow nulls and it still gives the message. Would anyone happen to know if there's any other binding that needs to be done or any special provisions with that type of control? Thanks in advance.
 
Is there anything I'm not including that I should be? I'm just wondering since I haven't had any replies yet and I've found people on this site to be very helpful with things in the past. Surely someone has come across this before, or something similar. Absolutely any insight would be very appreciated!
 
Thanks. I really appreciate the link! This might just be what I needed. Thanks again!
 
Here's something strange. I checked it using IsDBNull at runtime and it evaluated to false. Maybe it's something with the binding itself. Currently I have the Value property as the bound property. Also I will look again at my original query and make sure nothing weird is happening there. Thanks for helping me rule out the incoming value as the problem.
 
I am not getting the error anymore, but it still will not add data to the actual table. I have gone back in my table and set "Allow DBNull" to False and provided a default value for the column, but for some reason it still will not add to the table. I've checked the values of my DateTimePicker controls throughout the execution of the code and they are keeping the correct values. It could be something in the way I have the controls bound, but I'm not sure what to check for.
 
Try binding to the text property rather than the value.
 
I tried that too, but it did the same thing. Thanks for the suggestion, though.
 
how are you inserting the value into the database? Through a data adapter insert/update or through a command you have built in code? Is the database field able to hold date information?
 
It is a TableAdapter using an Update command writing to an SQL datetime field. The update command was automatically created by the TableAdapter Configuration Wizard.
 
I suspect there may be an issue with your SQL update command that was created by the wizard. Are you only updating records or are you creating new records, deleteing, etc. Each action has it's own command and associated SQL statement, but the wizard doesn't always know how to create them correctly, and you might need to tweak it or in some cases write your own in code.
 
I am doing all of the above (adding, updating, deleting, etc.) The SQL seems to work fine inside of the Query Builder, but I'll try defining my own statements. The strange thing is it works great on another form that I have, just not this one for some reason. I haven't been able to pinpoint what the difference is. I thought it was the DateTimePicker, but it may not be.
 
Not sure what to tell you. If you can test out your sql statement and it works, then I guess I am at a loss as to what is causing things not to update correctly.
 
It looks like the TableAdapter is updating successfully, but it is not carrying through to the table. Here is a snippet of my update code for new records:

Code:
Try
Me.Validate()
Me.CaseInputBindingSource.EndEdit()
  Try
    Me.CaseInputTableAdapter.Update(Me.CaseInputDataSet.CaseInput)
.
.
.

This seems to work fine in another form, but not this one.
 
I found the problem. My other tables had a connection property in the DataSet of "CaseInputConnectionString(MySettings)". However for some reason my CaseInput table had a connection property of "CaseInputConnectionString1(MySettings)". It's always something tiny but huge like one digit or letter being out of place that seems to cause the most problems. I appreciate the help. It helped me stay on the right track.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top