Home > Net >  ExecuteNonQuery ()
ExecuteNonQuery ()

Time:09-22



Conform to the requirements of the input data can be normal execution, messagebox can pop-up
Input is not in conformity with the requirements of the data is error (pictured)


How to let his failure insert tip MESSAGEBOX, rather than direct error
O great god answer

CodePudding user response:

It is obvious that you output parameter is a varchar, but database field type is smallint
You'll know it in print SQL statements,

CodePudding user response:

reference 1st floor is nu month god reply:
it is clear that your output parameter is a varchar, but database field type is smallint
You'll know it in print SQL statements,


I want to let the user input does not conform to the requirements of the data, displays a MESSAGEBOX prompt the user for wrong
Rather than an error


Type the correct do not conform to the requirements of the trigger will be an error

CodePudding user response:

In advance of parameters calibration
Or a try-catch statement execution

CodePudding user response:

You write messagebox statement execution wrote the try catch it inside the

CodePudding user response:

Like this:
String SQL="BEGIN TRANSACTION";
SQL +="update Score SET [#]='" + a +"', [SQL]='" + b + "', [Math]='" + c + "', [Web]='" + d + "' "+
"Where sno='" + stuNo +"' ";
SQL +="if @ @ error<> 0 RollBack the else commit ";
Try
{
If (ExecuteNoQuery (SQL) & gt; 0)
{
MessageBox. Show (" modify success!" );
Loadlist ();
}
}
The catch (Exception)
{
MessageBox. Show (" modify failed!" );
}

CodePudding user response:

The
reference 3 floor not fat to 130 do not change the response of the name:
in advance of parameters calibration
Or a try-catch statement execution


Thanks for a great god, and became

CodePudding user response:

The
reference 4 floor 姎 jacaranda response:
you write messagebox statement execution wrote the try catch it inside


Thanks for a great god, and became

CodePudding user response:

The
reference 5 floor 姎 jacaranda response:
like this:
String SQL="BEGIN TRANSACTION";
SQL +="update Score SET [#]='" + a +"', [SQL]='" + b + "', [Math]='" + c + "', [Web]='" + d + "' "+
"Where sno='" + stuNo +"' ";
SQL +="if @ @ error<> 0 RollBack the else commit ";
Try
{
If (ExecuteNoQuery (SQL) & gt; 0)
{
MessageBox. Show (" modify success!" );
Loadlist ();
}
}
The catch (Exception)
{
MessageBox. Show (" modify failed!" );
}


Thanks for a great god, and became

CodePudding user response:

You poor readability of the SQL statement, written in the actual project need parameterized SQL or stored procedures

CodePudding user response:

3 then reply

CodePudding user response:

And obviously database field type and do not match the item type you have written, type conversion failure
  • Related