Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: dbgrid not saving some data when fieldnames contain spaces in them



Permlink Replies: 1 - Last Post: Feb 9, 2016 10:33 AM Last Post By: Peter Below
john lmast

Posts: 22
Registered: 12/1/14
dbgrid not saving some data when fieldnames contain spaces in them
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 8, 2016 2:53 PM
Delphi XE7 Professional w/ Update 1 and (firedac / mobile packs) installed.
Windows 7 Home Premium

Hi, I've been at this all day to no avail.

I have an MS Access database that I am connected to through the dbgrid. Everything works well as expected. I mean, I can view the tables in the usual manor.

However, when any of the fields have a "space" in the fieldname, the data does not get written or updated back to the table.

Example:

field: Word
vs.
field: This Is A Word

The data in the Word column will get updated, but the data in the "This Is A Word" column will not. Instead, the dbgrid removes the data when I update it through code, and same results when using TAction.

I know that in the MS Acces IDE, when you work with queries, whenever you have a space in the fieldname, you have to pad them with "[]" thus, to get properly call the "This Is A Word" field, you have to enclose them like this: [this is a word] and everything works well. But this method does not work in delphi xe7 when I write the SQL string in a query control. Thus...

sSQL := 'Select Word, [This Is A Word] from tblWords'

This will display the data from the two fields, Word and [This Is A Word] in a dbgrid correctly, and when I edit any data in the Word column, it gets updated, BUT, when I edit any data in the [This Is A Word] column, it does not get updated.

I verified this issue by chaning the sql string to:

sSQL := 'Select [Word], [This Is A Word] from tblWords'

And it would no longer save any data in the [Word] column. And when i changed it back to Word, it worked again. That is, the data in the Word column was saved.

What am I not doing correctly to handle "spaces"in fieldnames ?
TIA
JohnLM

Edited by: john lmast on Feb 8, 2016 2:57 PM
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: dbgrid not saving some data when fieldnames contain spaces in them [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 9, 2016 10:33 AM   in response to: john lmast in response to: john lmast
john lmast wrote:

Delphi XE7 Professional w/ Update 1 and (firedac / mobile packs)
installed. Windows 7 Home Premium

Hi, I've been at this all day to no avail.

I have an MS Access database that I am connected to through the
dbgrid. Everything works well as expected. I mean, I can view the
tables in the usual manor.

However, when any of the fields have a "space" in the fieldname, the
data does not get written or updated back to the table.

Example:

field: Word
vs.
field: This Is A Word

The data in the Word column will get updated, but the data in the
"This Is A Word" column will not. Instead, the dbgrid removes the
data when I update it through code, and same results when using
TAction.

I know that in the MS Acces IDE, when you work with queries, whenever
you have a space in the fieldname, you have to pad them with "[]"
thus, to get properly call the "This Is A Word" field, you have to
enclose them like this: [this is a word] and everything works well.
But this method does not work in delphi xe7 when I write the SQL
string in a query control. Thus...

sSQL := 'Select Word, [This Is A Word] from tblWords'

This will display the data from the two fields, Word and [This Is A
Word] in a dbgrid correctly, and when I edit any data in the Word
column, it gets updated, BUT, when I edit any data in the [This Is A
Word] column, it does not get updated.

Try to enclose the field name in double quotes ("), that is actually
the more common form to deal with field names that contain spaces
(which is a bad idea to start with, by the way). But keep in mind that
this will make the field names *case sensitive*! SQL as such is not a
case-sensitive language.


--
Peter Below
TeamB

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02