DataRow - Spaces in Field Name - Problem!!

lorena

Well-known member
Joined
Oct 23, 2003
Messages
134
Location
Phoenix, Arizona
I am working on a windows form with a sql database that has several fields that have spaces in their names (NOT my idea or design but there it is). When the form loads, I want to bind the fields from the datarow to the controls on the form. I am running into problems because of the spaces.
Here is my code:
Code:
 guestDataRow = aGuestsDataSet.Guests.FindByPhone(phoneString)
    With Me
      .firstNameTextBox.Text = guestdatarow![first name].tostring
      .streetTextBox.Text = guestDataRow!street.ToString
      .cityTextBox.Text = guestDataRow!city.ToString
      .lastVisitTextBox.Text = guestDataRow!["last visit date"].ToString
    End With
None of the things I have tried worked and I would appreciate any help.
Thanks
 
Try using square brackets around column names. This works for table names as well.
Code:
.firstNameTextBox.Text = guestdatarow!["[first name]"].tostring

This may not be exactly right - Im not familiar with the "!" syntax of VB.NET. I was mostly pointing out the change to using [first name]

-ner
 
Suggestions

How about:

Code:
guestDataRow.Item("first name").ToString()

Or, as Nerseus suggested:

Code:
guestDataRow.Item("[first name]").ToString()

Im amazed they kept the ! syntax from VB6. :eek:
 
Thanks very much for your help. Here is the code that worked:
Code:
.firstNameTextBox.Text = guestDataRow.Item("first name").ToString
Thanks for your help!
 
Back
Top