Reading databound value

  • Thread starter Thread starter Vayse
  • Start date Start date
V

Vayse

In my code, I have lines like this

If Me.txtDeprLife.Text > iNumPeriods Then
stSQL = "SELECT * FROM qryPeriodSchedule WHERE DeprDate >= " &
gstfunAmerDate(Me.txtDeprStartDate.Text)

txtDeprLife is a text box bound to AssetsBinding source. txtDeprStartDate is
a datetime picker bound the same way.

Often, I am getting null values for these in my code. If the user edits any
field, none of the text boxes will be null. But they are otherwise.

How do I get around this? Is this some bug?

Thanks

Vayse
 
Just to give more info on this. My fields are on several tabs.
If I open the tab with txtDeprLife on it, it will have a value. I don't need
to edit any fields.
 
It may be that the value is not placed in the control until it is visible. I
don't know if this is the issue, or if my hypothesis is true.

However, the easiest way to avoid this problem, is to get the data from the
datasource, not the input control.
 
This seems the likely reason.
It would be best to read from the BindingSource or the TableAdapter. How do
would I read the current record from them?
 
Hi

We can use the code below to get the current datarowview. And then use the
Item approach to get the what the textbox currently binding to.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dr As DataRowView =
EmployeesBindingSource.CurrencyManager.Current
MsgBox(dr.Item("LastName").ToString())
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi

You are welcomed!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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