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