Home > Net >  Winform mysql written statement with the mysqlcommand input variable how to guarantee the variables
Winform mysql written statement with the mysqlcommand input variable how to guarantee the variables

Time:01-16

 string ReceiveMessagecom1="INSERT INTO history (time, operation) VALUES ('" + DateTime. Now. ToLocalTime (), ToString () + "', '" + ReceiveMessage +") "; 
such as the how to make the ReceiveMessage this variable is written in a string of code, but can not change the input to the stored in the database

CodePudding user response:

Using mediumtext field type
And then if the string contains double quotation marks when the incoming, single quotes, remember to escape

CodePudding user response:

Incoming content not sure you take this first try
 string ReceiveMessage=UPDATE ` brigade big 16-3 ` SET bar SET to complete the sign up='inspection declaration in the WHERE one pipe size=' DO - LDB01-35254-02 'AND line number=' 2 \ "- DO - 35254 - A2BZ - HT05 'AND joint number=' FW - 5 '
AND see how can successfully

CodePudding user response:

was not solved, feeling why you didn't go to think of the problem, then solve the problem of corresponding, I directly to you
String ReceiveMessage="UPDATE ` brigade big 16-3 ` SET bar SET to complete the sign up=', 'WHERE single pipe inspection central=' DO - LDB01-35068-02 'AND joint number=" FW - 10' AND line number="' - DO - 35068 - A2BZ - HT35 '";
String ReceiveMessagecom1="INSERT INTO history (time, operation) VALUES ('" + DateTime. Now. ToLocalTime (), ToString () + "', '" + ReceiveMessage +") ";

Using splicing SQL string, the need to deal with special characters, special characters and you here, is'
If you don't want to deal with special characters, it must use the parameter SqlParameter
String ReceiveMessage="UPDATE ` brigade big 16-3 ` SET bar SET to complete the sign up='inspection declaration in the WHERE one pipe size=' DO - LDB01-35068-02 'AND joint number=' FW - 10 AND line number='- DO - 35068 - A2BZ HT35 -'";
String ReceiveMessagecom1="INSERT INTO history (time, operation) VALUES (@ CTime, @ ReceiveMessage)";
List Param=new List () {
New SqlParameter (" @ CTime, "DateTime. Now),
New SqlParameter (" @ ReceiveMessage, "ReceiveMessage);
};
//or MySqlCommand CMD; CMD. The Parameters. AddWithValue (" @ CTime, "DateTime. Now);

CodePudding user response:

Don't think, even if you resolve this time, next time meet this problem or not

CodePudding user response:

reference wtnu200 reply: 3/f
was not solved, feeling why you didn't go to think of this problem, then solve the problem of corresponding, I directly to you
String ReceiveMessage="UPDATE ` brigade big 16-3 ` SET bar SET to complete the sign up=', 'WHERE single pipe inspection central=' DO - LDB01-35068-02 'AND joint number=" FW - 10' AND line number="' - DO - 35068 - A2BZ - HT35 '";
String ReceiveMessagecom1="INSERT INTO history (time, operation) VALUES ('" + DateTime. Now. ToLocalTime (), ToString () + "', '" + ReceiveMessage +") ";

Using splicing SQL string, the need to deal with special characters, special characters and you here, is'
If you don't want to deal with special characters, it must use the parameter SqlParameter
String ReceiveMessage="UPDATE ` brigade big 16-3 ` SET bar SET to complete the sign up='inspection declaration in the WHERE one pipe size=' DO - LDB01-35068-02 'AND joint number=' FW - 10 AND line number='- DO - 35068 - A2BZ HT35 -'";
String ReceiveMessagecom1="INSERT INTO history (time, operation) VALUES (@ CTime, @ ReceiveMessage)";
List Param=new List () {
New SqlParameter (" @ CTime, "DateTime. Now),
New SqlParameter (" @ ReceiveMessage, "ReceiveMessage);
};
//or MySqlCommand CMD; CMD. The Parameters. AddWithValue (" @ CTime, "DateTime. Now);


The line number is 2 "in the database - DO - 35013 - A2BZ HT05 - B but through to the variable becomes 2 " don't know how to - DO - 35013 - A2BZ HT05 - more than a B \ this how to solve

CodePudding user response:

Problem seems to be out in the translation part, other code number variable inside the pipeline without double quotes can be through, have double quotes is not a success, don't know how to solve

CodePudding user response:

reference 4 floor wtnu200 response:
don't ponder over a problem, even if you resolve this time, next time you meet this problem or not
bosses don't know how to solve

CodePudding user response:

Special characters, the need to escape, in vs, too, DO you think of this string string a="2" - DO - 35013 - A2BZ HT05 - B "right

CodePudding user response:

refer to the eighth floor wtnu200 response:
special characters, the need to escape, in vs, too, DO you think of this string string a="2" - DO - 35013 - A2BZ HT05 - B "right


Should be here and I \ \ "" + ReceiveMessage +" \ "lead to the problems, a value of 2" - DO - 35013 - A2BZ HT05 - B's words is right, but VS to translate so string a="2" - DO - 35013 - A2BZ HT05 - B "will be read into a separate string a=" 2 "is behind the error

CodePudding user response:

What you said is variable in vs viewer/" "" "" display in order to ", this is completely normal, variable viewer just shows the escape character, you won't have the string printed directly to the "/",

CodePudding user response:

references to the tenth floor hefei0603 response:
what you said is variable in vs viewer/" "" "" display in order to ", this is completely normal, variable viewer just shows the escape character, you won't have the string printed directly to the "/",
yes, but I am going to put this sentence inserted into the database, the string need to use quotation marks, and this led to a string of quotes and quotes outside echo, led to the error and how to avoid this situation

CodePudding user response:

Weixin_54582889
reference 11 floor response:
Quote: reference to the tenth floor hefei0603 response:
what you said is vs variable in the viewer/" "" "" display in order to ", this is completely normal, variable viewer just shows the escape character, you won't have the string printed directly to the "/",
yes, but I am going to put this sentence inserted into the database, the string need to use quotation marks, this led to a string of quotes and quotes outside echo, led to the error, how to avoid this kind of circumstance


If it was already a string object, it will have escape characters, you take this string object to a string with is not an error, but the splicing code string in your code with double quotes will need to escape,
  •  Tags:  
  • C#
  • Related