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 isCodePudding 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: