Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

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

  • *Experts*
Posted

Try using square brackets around column names. This works for table names as well.

.firstNameTextBox.Text = guestdatarow!["[first name]"].tostring

 

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

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Suggestions

 

How about:

 

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

 

Or, as Nerseus suggested:

 

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

 

I'm amazed they kept the ! syntax from VB6. :eek:

Never trouble another for what you can do for yourself.
Posted

Thanks very much for your help. Here is the code that worked:

.firstNameTextBox.Text = guestDataRow.Item("first name").ToString 

Thanks for your help!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...