Newbie: What does the value of a database bound textbox become when you clear the dataset?

  • Thread starter Thread starter Shanon Swafford
  • Start date Start date
S

Shanon Swafford

Thanks guys, I've gotten a lot of info from these groups but now I am stuck
again.

If there's a better or more efficient way, I'd like to hear them for my
"next release".

Here's what I have:

VB.NET working with an Access database.

DS_Customers1:
Dataset to hold customer names. I have a combobox and several textboxes
that are used to roll through this dataset.
DS_Customers_Locations1:
Dataset used to get customers locations for one customer. I have
a datagrid which gets filled by a query on each Customer_ID above. This
query and fill gets fired on a textbox value changing.
btn_Cus_Refresh:
Refresh Button to requery for new customers data
txtb_Cus_Customer_ID:
Bound to DS_Customers1 and feeds the query.

How it's supposed to work:
When the handle is created DS_Customers1 is filled which populates a
combobox of customer names and text boxes of their info. When you change
the selection in the combobox, the corresponding data changes. When the
customer_ID textbox changes textchanged event is fired which calls
Get_Customer_Locations() to get the locations associated with that customer.

The problem:
Everything works great except (I think) when DS_Customers1 is cleared,
txtb_Cus_Customer_ID is being set to something besides "", or
system.dbnull.value.

What value is this being set to so I can test for it?

Right now I get "Input string was not in a correct format." which is I
supposed this txtb_Cus_Customer_ID being passed to the
Me.OleDbSelectCommand2. I suspect that in the Refresh_Customer() sub,
DS_Customers1.Clear is setting txtb_Cus_Customer_ID from a valid number to
????? which fires the query. Then when the fill is done in the query is
fired again except that now I get "...Datareader already open".

I'd like to test for the cleared value inside Get_Customer_Locations() to
just skip the query, waiting on the ????? to valid number again that comes
with the fill.

How do I accomplish this.

Thanks Shanon

Code Below

Private Sub Refresh_Customer()
Cursor.Current = Cursors.WaitCursor
Try
Me.DS_Customers1.Clear()
Me.OleDbDa_Customers.Fill(DS_Customers1)
Catch ex As Exception
MessageBox.Show("Can't get Customer data from Database" & vbCrLf & ex.Message)
Finally
Me.OleDbConnection1.Close()
End Try
Cursor.Current = System.Windows.Forms.Cursors.Default
End Sub

Private Sub Get_Customer_Locations()
'********* I'd like to test here to be able to skip the ????? invalid value of the textbox.
If Me.txtb_Cus_Customer_ID.Text = ????? Then
Cursor.Current = Cursors.WaitCursor
Me.OleDbSelectCommand2.Parameters.Item("CustomerID").Value = Me.txtb_Cus_Customer_ID.Text
If Me.OleDbConnection1.State = ConnectionState.Closed Then
Try
Me.DS_Customers_Locations1.Clear()
Me.OleDbDa_Customers_Locations.Fill(DS_Customers_Locations1.tabCustomersLocations)
Catch ex As Exception
MessageBox.Show("Can't get Customer Location data from Database" & vbCrLf & ex.Message)
Finally
Me.OleDbConnection1.Close()
End Try
End If
Cursor.Current = System.Windows.Forms.Cursors.Default
End If ' skipped because textbox was invalid
End Sub

Private Sub tabCustomers_HandleCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabCustomers.HandleCreated
Refresh_Customer()
End Sub

Private Sub btn_Cus_Refresh_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_Cus_Refresh.Click
Me.Refresh_Customer()
End Sub

Private Sub txtb_Cus_Customer_ID_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles txtb_Cus_Customer_ID.TextChanged
If Me.chk_Get_Locations.Checked Then
Me.Get_Customer_Locations()
End If
End Sub
 
I found it 2 days later. For anyone that is looking is it "Nothing".

So it should be:
If Me.txtb_Cus_Customer_ID.Text = Nothing Then
.....
End If

I still get funky errors as it looks changes events are firing before the Connection can be closed but I'm getting there.
 
Back
Top