Home > Net >  An exception
An exception

Time:09-20

Why it is wrong to run, this executenonquery is very confused, two days, who is a great god to solve
Thank you thank you

CodePudding user response:

Very simple, there is something wrong with the SQL statement,
Catch:
1. Must be used in the SQL statement execution, no problem to copy the program to perform;
2. Write the code must be parameterized, don't splicing SQL.
Error writing (not that error, error prone, and there are safety concerns) :
insert into tableName (c1, c2) values (' ' '+ textBox1. Text +' ' ', ' ' '+ textBox2. Text +' ' ' ')
The correct writing:
string SQL="insert into tableName (c1, c2) values (@ c1, @ c2)";
SqlParameter spArr=new SqlParameter [] [] {
New SqlParameter (" @ c1, "textBox1. Text),
New SqlParameter (" @ c2, "textBox2. Text)
}
CMD. The Parameters. AddRange (spArr);
CMD. ExecuteNonQuery (SQL);

CodePudding user response:

I feel you see abnormal prompt, using the Chinese comma

CodePudding user response:

reference 1/f, gypsy song response:
is very simple, there is something wrong with the SQL statement,
Catch:
1. Must be used in the SQL statement execution, no problem to copy the program to perform;
2. Write the code must be parameterized, don't splicing SQL.
Error writing (not that error, error prone, and there are safety concerns) :
insert into tableName (c1, c2) values (' ' '+ textBox1. Text +' ' ', ' ' '+ textBox2. Text +' ' ' ')
The correct writing:
string SQL="insert into tableName (c1, c2) values (@ c1, @ c2)";
SqlParameter spArr=new SqlParameter [] [] {
New SqlParameter (" @ c1, "textBox1. Text),
New SqlParameter (" @ c2, "textBox2. Text)
}
CMD. The Parameters. AddRange (spArr);
CMD. ExecuteNonQuery (SQL);
fairy elder sister, still don't understand ah, I this just a buttton and a lable control

CodePudding user response:

refer to the second floor is nu month god reply:
I see abnormal tips, feel you use the Chinese comma
no! checked

CodePudding user response:

reference 4 floor qq_46357446 response:
Quote: refer to the second floor is nu month god reply:
I see abnormal tips, feel you use the Chinese comma
no! Checked

Then you take the keyword use [] enclosed,
Such as your [time], [pass]

CodePudding user response:

LZ, this tip you a look you should know is SQL spelled wrong right?
You are int rows to add a breakpoint debugging, here you can see you just write SQL statements, copy down, open the database management tools, new query, you make a copy of this statement, immediately will prompt you where is wrong, can get this done in minutes

CodePudding user response:

Reasonable, 6 l you're worth it

CodePudding user response:

refer to 7th floor eating it doesn't matter response:
reason, the practice of 6 l you're worth it
what do you mean

CodePudding user response:

Direct print the SQL to the database is not to know
  • Related