lorena Posted April 4, 2007 Posted April 4, 2007 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 Quote
*Experts* Nerseus Posted April 4, 2007 *Experts* Posted April 4, 2007 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 Quote "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
MrPaul Posted April 4, 2007 Posted April 4, 2007 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: Quote Never trouble another for what you can do for yourself.
lorena Posted April 4, 2007 Author Posted April 4, 2007 Thanks very much for your help. Here is the code that worked: .firstNameTextBox.Text = guestDataRow.Item("first name").ToString Thanks for your help! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.