Home > Net >  Turn to the great god: why Winform procedure does not perform this code directly to the next step
Turn to the great god: why Winform procedure does not perform this code directly to the next step

Time:11-18

I wrote a program, in the hope that judge backup successfully executed next, backup failure does not perform the next step, the backup successful implement the else statement of inside, but does not perform this paragraph, string selectsql1="exec PRO_UPDATE_CYRQ '" + zyh. Text +"', '" + CYRQ. Text + "', '" + loginid + "', '" + localaddr. ToString () + "' ";
SqlCommand cmd1=new SqlCommand (selectsql1, conn);//SqlCommand object allows you to specify the type of the operation on the database to perform,
Cmd1.Com mandType=CommandType. Text;
Int ret1=CMD. ExecuteNonQuery ();//the number of rows affected (total)
Directly displays the success
Complete code for the following
Private void button1_Click (object sender, EventArgs e)
{
//database connection string (quotes before the string to copy the character)
//Data source=server name, Initial catalog=database name, User Id=essentially a connection name,
//Password=Password database connections, integrated Security=True
String STR=@ "Data Source=. Initial catalog=. User Id=. Password=. Integrated Security=False ";
SqlConnection conn=new SqlConnection (STR);
Conn. The Open ();
String HostName=Dns. GetHostName ();
IPHostEntry localhost=Dns. GetHostByName (HostName);
IPAddress localaddr=localhost. Expressions such as AddressList [0].
String selectsql="SELECT * FROM ZY_BH0 WHERE ZYH='" + ZYH. Text +'"; ";
SqlCommand CMD=new SqlCommand (selectsql, conn);//SqlCommand object allows you to specify the type of the operation on the database to perform,
Cmd.Com mandType=CommandType. Text;
Int ret=CMD. ExecuteNonQuery ();//the number of rows affected (total)
If (ret==0)
{
MessageBox. Show (" backup fails, stop operation, please contact your administrator ");
return;
}
The else
{
String selectsql1="exec PRO_UPDATE_CYRQ '" + zyh. Text +"', '" + CYRQ. Text + "', '" + loginid + "', '" + localaddr. ToString () + "' ";
SqlCommand cmd1=new SqlCommand (selectsql1, conn);//SqlCommand object allows you to specify the type of the operation on the database to perform,
Cmd1.Com mandType=CommandType. Text;
Int ret1=CMD. ExecuteNonQuery ();//the number of rows affected (total)
If (ret1==0)
{
MessageBox. Show (" modify fails, please contact the administrator ");
return;
}
The else
{
MessageBox. Show (" modify success, discharge date is changed to "+ CYRQ. Text +" ");
}
Conn. Close ();
}
Conn. Close ();

}


I want to execute the stored procedure inside the

CodePudding user response:

Turn to the great god, help to see if the problem is

CodePudding user response:

Perform database operations (such as CMD ExecuteNonQuery (), the return value is not only and greater than 0, 0 and 1, if you have any error, the SQL statement is return 1, is also a backup failed, you can have a look at the return value adjustment, see if there is something wrong with the SQL statement,

CodePudding user response:

refer to the second floor ZSZhen response:
perform database operations (such as CMD. ExecuteNonQuery (), the return value is not only and greater than 0, 0 and 1, if you have any error, the SQL statement is return 1, is also a backup failed, you can have a look at the return value adjustment, see if there is something wrong with the SQL statement,


I'm debugging, return is 1, but it does not perform code

CodePudding user response:

Perform operations on a database type,
Cmd1.Com mandType=CommandType. Text;
Int ret1= CMD. ExecuteNonQuery ();//the number of rows affected (total)

CodePudding user response:

Set breakpoints, step by step run knew why

CodePudding user response:

Add a breakpoint debugging, step by step

CodePudding user response:

CMD to cmd1 stored procedure
  •  Tags:  
  • C#
  • Related