0

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?

Edited by leo88: n/a

4
Contributors
16
Replies
17
Views
6 Years
Discussion Span
Last Post by leo88
0

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.

0

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.

0

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

Edited by abelLazm: n/a

0

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~

0

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

example:
password
password

0

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

I had checked,just "Password" only :)

0

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.

Edited by leo88: n/a

0

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..

0

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:)

0

Hi abelLazm,thanks for help.

Edited by leo88: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.