Binding DateTimePicker

kimykimy

New member
Joined
Aug 11, 2006
Messages
4
Programming Experience
Beginner
Hi..

I'm trying to bind a DateTimePicker from a dataset, but getting a "cannot bind to property error". Here is the code. Please help...

Dim SqlAdapt As New OleDb.OleDbDataAdapter("select * from TBL", conn)
Dim ds As New DataSet

SqlAdapt.Fill(ds)
datetimepickerW.DataBindings.Add("Value", ds, "DATE")

Textboxes work perfectly but I can't get this datetimepicker to work.
Thanks alot guys...
 
You are attempting to bind to the 'DATE' property of the dataset. You should be binding to the date field in a table contained in the dataset.
Datasets don't contain data directly. Datasets contain datatables and the dataTables contain the data in the form of dataRows and their items. (Datasets can optionally contain relations.)
Look at the code you used to bind the textboxes. Is the second parameter ds? I would think it would be ds.TableName where TableName is the name of the table in the dataset. It could be in a number of different formats depending on how you have things set up.
 
thanks for the tip... I've changed the field name to WDATE in the table (ms-access) and used a data table in place of a dataset, but still getting the same error. I've also included the code to bind TEXT field. What am I doing wrong? Thanks alot


Dim SqlAdapt As New OleDb.OleDbDataAdapter("select * from TBL", conn)
Dim dt As New DataTable

SqlAdapt.Fill(dt)
datetimepickerW.DataBindings.Add("Value", dt, "WDATE")

'code for binding a text field
'txtNAME.DataBindgs.Add("TEXT",dt,"LNAME")
 
... I've changed the field name to WDATE in the table ...
I should have mentioned that. You should never use certain reserved words as Field names and Date is a reserved word. Here is a link to a page that has links to reserved words for several types of database: Reserved words for various databases

Perhaps you misunderstood my previous post; you didn't have to change to a datatable. Although if you are only using one table in the dataset then only a dataTable will suffice.

Is the WDATE field in Access a dateTime field?
 
Yes, its a short datetime field. I've read other posts regarding this issue and the following code should resolve the issue, but I am unclear on exactly what/how a bindingsource works? Any idea on how I can implement a bindingSource with the limited code I've provided? Thanks for the help...


this._theDatePicker.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.bindingSource1, "ShippedDate", true));
 
Back
Top