hi, I wants to do register function in window form application microsoft visual studio 2008 and insert the data into microsoft Access 2007 table by using C#. Below is my codes:

SQLStr = "INSERT INTO RegisterEmployee(EmployeeName,Password,Gender,ContactNumber)" +
                         "VALUES ('" +
                          SQLStrCmd.ReplaceStr(nameReg.Text) + "', '" +
                          SQLStrCmd.ReplaceStr(passReg.Text) + "', '" +
                          SQLStrCmd.ReplaceStr(genReg.Text) + "', '" +                           
                          SQLStrCmd.ReplaceStr(Hptxt.Text) + "')";

When I execute, i found that password cannot insert into database and got sql exception, when I remove password in codes above, other columns able to be inserted.After that i try the sql command in the Microsoft Access, its sql output is like below:

INSERT INTO RegisterEmployee ( EmployeeName, [Password], Gender, ContactNumber )
// Values command

Why would have the "[]" symbol for the password? what is the meaning? Is this condition made my password cannot inserted?

Do your sequence of inserting is correct?

Do your sequence of inserting is correct?

hi Lam,

It is correct, but now is already ok, I needs to add "[]" symbol in my program("[Password]"), it is able to insert now but I still don't understand what is the meaning of the symbol, hope somebody can guide me, thanks in advance.

To define them as fields, in case they are actually keywords

But other columns don't need to put the "[]" symbol, just the password column needed, if i have no put on the password in my program, then my sql command will get error.

When u create the table, did you put[]?
please check..=)

why putting an [] with password? strange i never encountered such a problem should look into it

To leo88, if incase u really create table without [].
Then, this is your answer:
If a field name includes a space or some other nonalphanumeric character, you must enclose that field name within square brackets ([ ]).

have a nice day~

I believe when you are creating your password field, there is some space within your password column.

example:
password
password

When u create the table, did you put[]?
please check..=)

I had checked,just "Password" only :)

"Password"? or "Password "
Haha, check?

why putting an [] with password? strange i never encountered such a problem should look into it

In the table, i had not put the symbol, but when i run the sql inside the Microsoft Access, then it will appeared "[Password]" in the sql command, then I needs to put the symbol in my program, then it just able to be inserted, now already done the register module, but had left some question about the condition.

Just "Password" :)

Hi Leo, As stefan said the word password is a keyword so they should be enclosed in [],

Even i got an exception when my column name was Region,


Mark it as solved if it is..

Hi Leo, As stefan said the word password is a keyword so they should be enclosed in [],

Even i got an exception when my column name was Region,


Mark it as solved if it is..

Hi samueal,
I see, means it will appeared the symbol when encounter keyword in column,I understand now, Thanks you everyone:)

Hi abelLazm,thanks for help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.