通过ExecuteNonQuery()的返回值来判断操作数据库的成功与否是可以的.但是要分情况. 1.ExecuteNonQuery() 不执行存储过程. 此时如果对数据库执行,插入,更新,删除操作,返回的是 受影响的行数.(及一个大于等于0的整数) 2.ExecuteNonQuery() 执行查询不返回影响的行数. 2.ExecuteNonQuery 执行存储过程. [1].存储过程有...
executenonquery---返回影响的行数,与存储过程return返回值无关,sql输出参数无关 return返回值---要用cmd.parameters["@return"].value读取 sql输出参数---要用cmd.parameters["@output"].value读取
command.ExecuteNonQuery() list = CInt(p.Value) '取得存储过程的返回值 Catch ex As Exception Finally connection.Close() End Try Return list '返回值 End Using End Using End Function === 返回存储过程OUTPUT参复和RETURN返回值的原代码 --- ALTER PROCEDURE sp_2 @p int output, @p1 int, @p2 in...
Although theExecuteNonQueryreturns no rows, any output parameters or return values mapped to parameters are populated with data. For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1...
cmd.ExecuteNonQuery(); string value = cmd.Parameters["@return"].Value.ToString();//把返回值赋值给value if (value == "1") { Label1.Text = "添加成功"; } else { Label1.Text = "添加失败"; } } 1. 2. 3. 4. 5. 6. 7.
Parameters.Add("@Sno",SqlDbType.Char,5).Value=txtSno.Text; cmd.Parameters.Add("@returnValue",SqlDbType.Int).Direction=ParameterDirection.ReturnValue;//返回的状态值 cmd.ExecuteNonQuery(); MessageBox.Show(cmd.Parameters["@returnValue"].Value.ToString());//获取存储过程向调用者返回的状态值 }
{7}')",userLogin,userPass,userNicename,userEmail,userStatus,displayName,userUrl,userActivationKey);varcmd=newSqlCommand(sql,conn);cmd.ExecuteNonQuery();/// Because this call to Close() is not wrapped in a try/catch/finally clause,/// it could be missed if an exception occurs above. Don...
BeginExecuteNonQuery() Source: System.Data.SqlClient.notsupported.cs Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this SqlCommand. C# Copy public IAsyncResult BeginExecuteNonQuery(); Returns IAsyncResult An IAsyncResult that can be used ...
();returncmd.ExecuteNonQuery(); } } }// Set the connection, command, and then execute the command and only return one value.publicstaticObjectExecuteScalar(String connectionString, String commandText, CommandType commandType,paramsSqlParameter[] parameters){using(SqlConnection conn =newSqlConnection(...
publicIAsyncResultBeginExecuteNonQuery(); Returns IAsyncResult AnIAsyncResultthat can be used to poll or wait for results, or both; this value is also needed when invokingEndExecuteNonQuery(IAsyncResult), which returns the number of affected rows. ...